July 25, 2003

GCC flag of the day

I was perusing my codebase and I noticed a number of places where virtual methods from a parent class were being masked by virtual methods from the child class (e.g. ParentClass has a virtual method foo(int i=8). ChildClass is a ParentClass and has a virtual method foo(void)).

If you have:
Child myChild;
Parent *pParent = &myChild;

myChild.foo();
pParent->foo();

pParent->foo() is not calling the same routine as myChild.foo().

This can be detected by using the -Woverloaded-virtual flag when compiling files. Note that this doesn't warn if a nonvirtual method in child masks the parent method (presumably the nonvirtual method in ChildClass would indicate that things are supposed to work the way they do).

Posted by matt at July 25, 2003 03:59 AM
Comments

So not a techie: Upon first glancing at this entry, I of course skipped to the programming part, and I thought you were trying to illustrate some parent/child dynamic, or some family relationship thing. Heh. Silly me.

Also, why are you posting at 4 AM? Is that 4 AM your time or mine? (Not that I haven't been online at 4 AM in previous years...)

Posted by: Naomi at July 25, 2003 10:56 AM

yes, it was really 4am his time. No, he didn't have a good reason (unless you count Nethack as a good reason to be up really late.)

Posted by: Angela at July 25, 2003 10:40 PM

Neferet the Green requires my aid to defeat The Dark One and recover the Eye of the Aethiopica. Sleep is but a secondary concern.

Posted by: matt at July 26, 2003 11:55 AM