我在头文件中有一个类:
class Employee
{
//Private data members
private:
string firstName;
string lastName;
char gender;
//number of employees
const static int numEmployees = 0;
public:
....
};
愚蠢的事情是在教练的“指南”中说,在类的私有成员中将 numEmployees 声明为 0 的静态整数值
问题是我不能更新numEmployees变量,因为它是const,例如当你公开声明构造函数时:..你不能增加numEmployees = numEmployees + 1。
如果您不声明numEmployees为const,则只需在static int numEmployees;Visual Studio 2010 中给出错误说只会const在类中声明。
知道如何申报numEmployees吗?谢谢!