Вы не можете сделать это с sizeof()
, используйте std::is_empty
, например:
#include <iostream>
#include <type_traits>
struct EmptyStruct {};
struct CharStruct { char c; };
int main(void)
{
std::cout << std::boolalpha;
std::cout << "EmptyStruct " << std::is_empty<EmptyStruct>::value << '\n';
std::cout << "CharStruct " << std::is_empty<CharStruct>::value << '\n';
return 0;
}
Выход:
EmptyStruct true
CharStruct false
как прокомментировал @RichardCritten.