Can I get the size of a struct field w/o creating an instance of the struct?

You can use an expression such as:

sizeof Foo().bar

As the argument of sizeof isn’t evaluated, only its type, no temporary is actually created.


If Foo wasn’t default constructible (unlike your example), you’d have to use a different expression such as one involving a pointer. (Thanks to Mike Seymour)

sizeof ((Foo*)0)->bar

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)