This is an online C++ test question, which has been done.
#include
using namespace std;
class A
{
};
class B
{
int i;
};
class C
{
void
why not try printing out the layout? From system V abi
for example (put your code and remember to apply sizeof to the type you want to check)
struct Base1 {
virtual int method_base_11() {
return 11;
}
virtual ~Base1() = default;
};
struct Base2 {
virtual int method_base_21() {
return 22;
}
virtual ~Base2() = default;
};
struct Foo: public Base1, public Base2 {
int a;
};
int main() {
Foo foo;
foo.method_base_21();
return sizeof(Foo);
}
output,
$ clang -cc1 -std=c++11 -fdump-record-layouts foo.cc
*** Dumping AST Record Layout
0 | struct Base1
0 | (Base1 vtable pointer)
| [sizeof=8, dsize=8, align=8,
| nvsize=8, nvalign=8]
*** Dumping AST Record Layout
0 | struct Base2
0 | (Base2 vtable pointer)
| [sizeof=8, dsize=8, align=8,
| nvsize=8, nvalign=8]
*** Dumping AST Record Layout
0 | struct Foo
0 | struct Base1 (primary base)
0 | (Base1 vtable pointer)
8 | struct Base2 (base)
8 | (Base2 vtable pointer)
16 | int a
| [sizeof=24, dsize=20, align=8,
| nvsize=20, nvalign=8]