RSS Forums RSS
Please support our C advertiser: Programming Forums
Views: 354 | Replies: 1
Reply
Join Date: May 2005
Posts: 21
Reputation: gpta_varun is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
gpta_varun gpta_varun is offline Offline
Newbie Poster

Question Need 4 destructors !!

  #1  
Mar 20th, 2007
Hi All ..

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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2006
Location: Canada
Posts: 4,545
Reputation: John A is a name known to all John A is a name known to all John A is a name known to all John A is a name known to all John A is a name known to all John A is a name known to all 
Rep Power: 17
Solved Threads: 284
Moderator
Featured Blogger
John A's Avatar
John A John A is offline Offline
Vampirical Moderator

Re: Need 4 destructors !!

  #2  
Mar 20th, 2007
>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 .
tuxation.com - Linux articles, tutorials, and discussions
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:14 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC