我不明白为什么静态私有变量在我的代码中不起作用!这是代码:
#include<iostream>
#include<string>
using namespace std;
class KittyCat{
private:
int a;
string t;
static int count;
public:
KittyCat(){
a=0;
t="NULL";
count++;
}
void set(int i, string m){
a=i;
t=m;
}
void show(){
cout << "A is: "<< a <<" T is: " << t <<"\n\n";
}
void totalCount(){
cout <<"Total Counts: "<< count <<"\n\n";
}
};
void main(){
KittyCat tech, review, article, photo, video;
tech.set(10, "Technology");
review.set(85, "Reviews");
article.set(54, "Articles");
article.show();
article.totalCount();
}
有任何想法吗?