Re: Question on virtual inheritance
ambarish.mitra@gmail.com wrote:
#include <iostream>
class base {
public: virtual void f() {}
};
class derived: public virtual base {
};
int main()
{
std::cout << "size of base = " << sizeof(base) <<
std::endl; /* =4 . This is Okay.*/
std::cout << "size of derived = " << sizeof(derived) <<
std:endl; /* 4 or 8 */
}
In MS environment (Visual Studio 6/7), the output is coming as 8,
whereas in g++ compiler (g++ 3.4.5), the output is coming as 4.
Can any1 tell how the internals work out for virtual inheritance in
these 2 compilers? (I hv checked that size of pointer =4 in both
systems).
Yes, somebody in a G++ newsgroup can tell you about the internals
of the G++ object model and somebody in a VC++ newsgroup can tell
you the internals of the VC++ object model. They are compiler-
specific, implementation detail, yadda-yadda, off-topic really.
A pointer to the virtual base class subojbect[s] is usually stored
in the class (just like a pointer to the virtual function table),
but that's not mandated by the Standard. For all we know, G++ can
see that you only have a single class virtually inheriting from
your base and not store that pointer, and VC++ does store it with
no regard to the completeness of the hierarchy. But that's just
speculation. To know for sure, post to the newsgroup for each
compiler.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask