Why are C++ classes allowed to have zero data members?

前端 未结 6 2151
遥遥无期
遥遥无期 2020-12-20 16:46

question about c++ why minimal number of data members in class definition is zero

i think it should be one , i.e pointer to virtual table defined by compiler

6条回答
  •  青春惊慌失措
    2020-12-20 17:26

    Well, actually C++ mandates that all classes must occupy some space (You need to be able to generate a pointer to that class). They only need a pointer to a vtable though, if the class is polymorphic. There's no reason for a vtable at all in a monomorphic class.

提交回复
热议问题