I know this may sound like a strange question, but I'm just wondering if a class in C ++ weighs more than a structure with the same data fields, and this one thing I could not find the answer for ... <w > Consider this:
struct SomeStruct { int a; int b; }; class SomeClass { public: SomeClass():a(0),b(0){} private: int a; int b; }; int main() { std::cout<<sizeof(SomeStruct)<<std::endl;
But now let's see what happens when I add a destructor to SomeClass:
struct SomeStruct { int a; int b; }; class SomeClass { public: SomeClass():a(0),b(0){} virtual ~SomeClass(){} private: int a; int b; }; int main() { std::cout<<sizeof(SomeStruct)<<std::endl;
Why does SomeClass need another 8 bytes for the destructor?
c ++ destructor
so.very.tired
source share