c++
Lnk112
LNK200
为什么会产生报错,如何解决
#include <iostream>
using namespace std;
class Student {
private:
static int count;
char name;
public:
static void getCount(int judge);
Student() {
cout << "请输入学生姓名";
cin >> name;
getCount(1);
}
~Student() {
cout << "该生信息已删除";
getCount(0);
}
};
int main() {
Student a, b;
return 0;
}
void Student::getCount(int judge){
if (judge)
count++;
else
count--;
cout << "共有学生" << count << "名";
}
static静态成员变量了解一下,static修饰的作用,以及它怎么用。
所有类对象共用这个static变量,需要在外部做初始化,可以百度学习一下整个的具体细节。
这里代码需要加上初始化: