static constant members for array size

前端 未结 5 757
一生所求
一生所求 2021-02-09 15:54

MyClass.h

class MyClass
{
public:

static const int cTotalCars;

private:

int m_Cars[cTotalCars];
};

MyClass.cpp

5条回答
  •  有刺的猬
    2021-02-09 16:11

    It just can't works if you define size of the array is set in cpp file. All class clients should know the size of class instance but they just have no idea about .cpp file because you only put #include "MyClass.h" in client-files.

    In other words - your class definition is varies depending on the cpp-file which is not used while compile files that uses MyClass.

提交回复
热议问题