Please support our C advertiser: Programming Forums
Views: 354 | Replies: 1
![]() |
•
•
Join Date: May 2005
Posts: 21
Reputation:
Rep Power: 4
Solved Threads: 0
Hi All ..
consider the case :
We have implicit destructors defined , when their actual definition is absent .
Does that mean , that when we delete a Base class pointer , pointing to a derived class , the actual memory assigned to the derived class is not released.
Is that a memory Leak ???
-varun
consider the case :
class test {
public :
int a;
test();
}
class test_derv : public test
{
public:
int a;
};
void main()
{
test * pctest = new test_derv;
delete pctest;
}
We have implicit destructors defined , when their actual definition is absent .
Does that mean , that when we delete a Base class pointer , pointing to a derived class , the actual memory assigned to the derived class is not released.
Is that a memory Leak ???
-varun
>We have implicit destructors defined , when their actual definition is absent .
No, since you declared the constructor, you're going to have to define it too, or else you're going to get linker errors.
>Does that mean , that when we delete a Base class pointer , pointing to a derived class , the actual memory assigned to the derived class is not released.
Yep.
>Is that a memory Leak ???
Yep. To fix the problem, look into virtual destructors .
No, since you declared the constructor, you're going to have to define it too, or else you're going to get linker errors.
>Does that mean , that when we delete a Base class pointer , pointing to a derived class , the actual memory assigned to the derived class is not released.
Yep.
>Is that a memory Leak ???
Yep. To fix the problem, look into virtual destructors .
tuxation.com - Linux articles, tutorials, and discussions
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode