By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,614 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

gcc warnings again

P: n/a
warning: 'class gdt_manager' has virtual functions but non-virtual
destructor

what does this mean? how to fix it?

thanks.

Jun 26 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
asdf wrote:
warning: 'class gdt_manager' has virtual functions but non-virtual
destructor

what does this mean? how to fix it?


http://www.parashift.com/c++-faq-lit....html#faq-20.7
"When should my destructor be virtual?"

Answer: Always, unless you find a reason to take the virtual out.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Jun 26 '06 #2

P: n/a
asdf wrote:
warning: 'class gdt_manager' has virtual functions but non-virtual
destructor

what does this mean?
That the class gdt_manager has virtual functions but non-virtual destructor.
how to fix it?


By making its destructor virtual.

Jun 26 '06 #3

P: n/a

warnings are not equal to error. you should make destructor virtual.
but not must

Jun 26 '06 #4

P: n/a

海风 wrote:
warnings are not equal to error. you should make destructor virtual.
but not must


destructors should always be virtual functions in order to properly get
invoked.

Jun 26 '06 #5

P: n/a
zj****@gmail.com wrote:

海风 wrote:
warnings are not equal to error. you should make destructor virtual.
but not must


destructors should always be virtual functions in order to properly get
invoked.


Only if the object is destroyed polymorphically.

Jun 26 '06 #6

P: n/a
Rolf Magnus wrote:
zj****@gmail.com wrote:
海风 wrote:
warnings are not equal to error. you should make destructor virtual.
but not must

destructors should always be virtual functions in order to properly get
invoked.


Only if the object is destroyed polymorphically.


Yep. On my current project, I'm fighting the "all destructors must be
virtual" directive, on the grounds that we don't actually do any dynamic
allocation, and therefore a virtual destructor is unnecessary.
Jun 26 '06 #7

P: n/a
red floyd wrote:
Rolf Magnus wrote:
zj****@gmail.com wrote:
海风 wrote:

warnings are not equal to error. you should make destructor virtual.
but not must

destructors should always be virtual functions in order to properly get
invoked.

Only if the object is destroyed polymorphically.

Yep. On my current project, I'm fighting the "all destructors must be
virtual" directive, on the grounds that we don't actually do any dynamic
allocation, and therefore a virtual destructor is unnecessary.


What's the harm in making the destructor virtual?

Joe
Jun 26 '06 #8

P: n/a
* zj****@gmail.com:
?? wrote:
warnings are not equal to error. you should make destructor virtual.
but not must


destructors should always be virtual functions in order to properly get
invoked.


Too bad the standard library's classes generally don't have virtual
destructors. Unusable. Oh well.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jun 26 '06 #9

P: n/a
Joe Van Dyk wrote:
[..]
What's the harm in making the destructor virtual?


You mean, besides potential performance hindrance?
Jun 26 '06 #10

P: n/a

warnings are not equal to error. you should make destructor virtual.
but not must


use virtual to make sure the destructor will be excuted, but it costs a
pointer in vtbl.
Jun 27 '06 #11

P: n/a
"William" <wi*****@xxx.com> writes:

warnings are not equal to error. you should make destructor virtual.
but not must


use virtual to make sure the destructor will be excuted, but it costs a
pointer in vtbl.


Unless you are working under SEVERE memory constraints (e.g. in an embedded
system) this is a non-issue since there is only one vtbl per class with
virtual functions.

Jun 28 '06 #12

P: n/a
In article <xv*************@Psilocybe.Update.UU.SE>,
jo****@Student.DoCS.UU.SE says...

[ ... ]
Unless you are working under SEVERE memory constraints (e.g. in an embedded
system) this is a non-issue since there is only one vtbl per class with
virtual functions.


Any virtual function also (typically) means that each object has to
carry a pointer to the vtable. In some cases that's simply
unacceptable -- consider (for example) building a text editor, and
wrapping each character in a class. The total size of the class sans
virtual dtor is typically 8 bits. On a 64-bit system, the vtable
pointer would increase that to 72 bits, and that might easily cause
padding to be added, so the total size goes up to 128 bits.

Mulitply that overhead by the number of characters in a text file,
and you've got a text editor almost as efficient as emacs on an 8-bit
microcontroller.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jun 29 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.