As stated, the question doesn't really make sense -- an instance has a size, but a class really doesn't. Since you can't create an instance, "the size" is mostly a meaningless concept. You can use sizeof(A)
, but the result doesn't mean much -- thanks to the empty base class optimization (for one obvious example), sizeof(A)
does not necessarily tell you how much using A
as a base class will contribute to the size of a derived class.
For example:
#include <iostream>
class A {};
class B {};
class C {};
class D {};
class Z : public A, public B, public C, public D {};
int main() {
std::cout << "sizeof(A) = " << sizeof(A);
std::cout << "sizeof(Z) = " << sizeof(Z);
return 0;
}
If I run this on my computer, sizeof(A)
shows up as 1. The obvious conclusion would be that sizeof(Z)
must be at least four -- but in reality with the compilers I have handy (VC++, g++), it shows up as three and one respectively.