static constant members for array size

前端 未结 5 857
一生所求
一生所求 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:12

    I would rather use a #define C_TOTAL_CARS 5, then static const int cTotalCars = C_TOTAL_CARS; and then also, int m_Cars[C_TOTAL_CARS];.

提交回复
热议问题