Regarding error thrown by sizeof(class) usage in C++ -
when compile project in c++, following error thrown msvc :
error #94: size of array must greater zero
the error thrown in following line on doing sizeof :
if (sizeof (mynamespace::myclass) == 60) myclass defined :
class myclass: public parentclass { public: myclass( void *pcreate, int a, int b, bool c) : parentclass( pcreate, a, b, c ) {} virtual inline void myfunc ( ) { //something } private: virtual ~myclass(){}; /** * copy assignment. intentionally made private , not implemented prohibit usage (noncopyable stereotype) */ myclass& operator=(const myclass&); }; can tell me might wrong? if sizeof returns 0 size, why compiler error?
this error caused when take sizeof of class that's declared @ point. e.g. class myclass; const size_t error = sizeof(myclass);.
note doesn't matter whether class defined later: definition must precede sizeof.
Comments
Post a Comment