Size of C++ classes

前端 未结 3 1434
予麋鹿
予麋鹿 2021-02-07 12:06

Here is the code which prints size of different classes

#include 

using namespace std;

class EmptyClass
{    
};

class AbstractClass
{
  publi         


        
3条回答
  •  囚心锁ツ
    2021-02-07 12:42

    NotAbstrClass has no data members, so it too is an empty class. Since classes cannot be zero-sized, you get the same treatment as EmptyClass.

    MixClass has a virtual function, and 1 non-static data member. It seems each of these (vptr and int) occupy 4 bytes on your platform, so the size is 8 bytes.

提交回复
热议问题