C++通过类名调用静态变量为何错误?

#include<iostream>
using namespace std;
class A
{

public:int x;
int y;
static int count;
public :
A(int x1 =0,int y1=0)
{
x = x1;
y = y1;
}
A(const A &m)
{
x = m.x;
y = m.y;
}
~A()
{
cout << "construct destroyed" << endl;
count++;
}
};
int A::count = 0;
A g()
{
A a1(1, 2);
return a1;
}
void main()
{
g();
cout << A.count;
}
窝试图通过COUNT来计算析构函数的执行次数,但是无法调用,请问这是为何?通过类名难道不可以调用静态变量吗?请详细解答。

应该这样子写
cout << A::count;
温馨提示:答案为网友推荐,仅供参考
相似回答