I know that sizeof
is a compile-time calculation, but this seems odd to me: The compiler can take either a type name, or an expression (from which it deduces the type). But how do you identify a type within a class? It seems the only way is to pass an expression, which seems pretty clunky.
struct X { int x; };
int main() {
// return sizeof(X::x); // doesn't work
return sizeof(X()::x); // works, and requires X to be default-constructible
}