Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > virtual destructor

Reply
Thread Tools

virtual destructor

 
 
Pradeep Patra
Guest
Posts: n/a
 
      07-03-2009
Hi all,
If I have the following situation: I have a class A which doesnot
have any virtual functions . If I will declare the destructor as
virtual will that cause any problem? like memory leak etc?

Class B;
class A
{
public:
A();
virtual ~A();

private:
B* b;

}



 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      07-03-2009
* Pradeep Patra:
> Hi all,
> If I have the following situation: I have a class A which doesnot
> have any virtual functions . If I will declare the destructor as
> virtual will that cause any problem? like memory leak etc?


No.


Cheers & hth.,

- Alf
 
Reply With Quote
 
 
 
 
Juha Nieminen
Guest
Posts: n/a
 
      07-03-2009
Pradeep Patra wrote:
> If I have the following situation: I have a class A which doesnot
> have any virtual functions . If I will declare the destructor as
> virtual will that cause any problem? like memory leak etc?


I'm curious to know why you think making the destructor virtual could
cause a memory leak.
 
Reply With Quote
 
Yan
Guest
Posts: n/a
 
      07-03-2009
On Jul 3, 7:53*am, Pradeep Patra <smilesonisa...@gmail.com> wrote:
> Hi all,


> If I will declare the destructor as
> virtual will that cause any problem? like memory leak etc?
>


no. on the contrary, leaving your destructor non-virtual may cause
memory leaks. the only downside of declaring your destructor virtual
(since that would be the first virtual method in the class) is that
most likely the size of the objects of this class will become larger
by the size of the virtual pointer. I doubt it matters in 99.99% of
the cases though.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compiler generated destructor vs class implemented destructor arun C++ 2 06-13-2006 05:43 AM
Can abstract base class have V-table?, Will the pointer to virtual destructor be entered into the virtual table? sojin C++ 12 04-07-2006 09:02 AM
Explicit destructor calls from inside base class destructor frs C++ 20 09-21-2005 09:22 AM
Virtual destructor for virtual base class? Chunhui Han C++ 2 06-24-2004 10:13 AM
virtual destructor Vs virtual method Calvin Lai C++ 7 12-18-2003 03:11 AM



Advertisments