Force all classes to implement / override a ‘pure virtual’ method in multi-level inheritance hierarchy

I found one mechanism, where at least we are prompted to announce the overridden method explicitly. It’s not the perfect way though. Suppose, we have few pure virtual methods in the base class B: class B { virtual void foo () = 0; virtual void bar (int) = 0; }; Among them, suppose we want … Read more

C++ object size with virtual methods

This is all implementation defined. I’m using VC10 Beta2. The key to help understanding this stuff (the implementation of virtual functions), you need to know about a secret switch in the Visual Studio compiler, /d1reportSingleClassLayoutXXX. I’ll get to that in a second. The basic rule is the vtable needs to be located at offset 0 … Read more

What is the first (int (*)(…))0 vtable entry in the output of g++ -fdump-class-hierarchy?

Those are the offset-to-top (needed for multiple inheritence) and typeinfo (RTTI) pointers. From the Itanium ABI (you are not using the Itanium compiler, but their description of this is really good): The offset to top holds the displacement to the top of the object from the location within the object of the virtual table pointer … Read more