gcc warnings again

A

asdf

warning: 'class gdt_manager' has virtual functions but non-virtual
destructor

what does this mean? how to fix it?

thanks.
 
R

Rolf Magnus

asdf said:
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.
 
Z

zjlhxq

海风 said:
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.
 
W

William

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.
 
R

red floyd

Rolf said:
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.
 
J

Joe Van Dyk

red said:
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
 
A

Alf P. Steinbach

* (e-mail address removed):
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.
 
J

Johan Bengtsson

William said:
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.
 
J

Jerry Coffin

[ ... ]
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top