Re: Odd error with g++
- From: Roger Leigh <${rleigh}@invalid.whinlatter.ukfsn.org.invalid>
- Date: Sun, 22 Jan 2006 12:29:35 +0000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
"David Schwartz" <davids@xxxxxxxxxxxxx> writes:
> "elitecodex" <elitecodex@xxxxxxxxx> wrote in message
> news:1137871047.763997.136900@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
>> Fixed it.
>>
>> I did a little bit more research and just tried something... and it
>> worked. I just added virtual to my deconstructor.
>>
>> Any ideas as to why that would fix it? What does the deconstructor
>> being virtual have to do with a method of being virtual?
>>
>> Thanks for your help
>
> G++ needs to create one and only one copy of the vtable for the
> class. If you give it no way to find one place to do that, then it
> will choke. I believe G++'s heuristic is to create the vtable in
> whatever code file implements the first virtual function. By making
> the destructor virtual and implementing it, you make that heuristic
> work.
I've just checked this, and it appears to emit a vtables for derived
classes in translation units which implement a derived class, in
addition to the class vtable. I'm not certain, but I think this only
happens when you "chain up" to a parent class method, since this then
requires the parent vtable.
For templated classes, the vtables appear to be present in all
translation units instantiating the class.
In both these cases, the vtables have "V" (weak object, or "vague")
linkage, so they should be collapsed to a single instance at link
time.
Regards,
Roger
- --
Roger Leigh
Printing on GNU/Linux? http://gutenprint.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8+ <http://mailcrypt.sourceforge.net/>
iD8DBQFD03quVcFcaSW/uEgRAksoAJoDZnzhp2j5cE3FLM1FjMBPL9oLUACeLJ2W
X/wzoLdD97OTQlCNOe4J6mM=
=41LS
-----END PGP SIGNATURE-----
.
- References:
- Odd error with g++
- From: elitecodex
- Re: Odd error with g++
- From: David W Noon
- Re: Odd error with g++
- From: elitecodex
- Re: Odd error with g++
- From: elitecodex
- Re: Odd error with g++
- From: David Schwartz
- Odd error with g++
- Prev by Date: Re: Odd error with g++
- Next by Date: fork question
- Previous by thread: Re: Odd error with g++
- Next by thread: PF_PACKET Socket
- Index(es):