输出
Addres of Value:009C022C
1 1
Addres of Value:009C022C
2 1
Addres of Value:009C022C
3 2
请按任意键继续. . .
#include<iostream>
using namespace std;
class A
{
public:
A ()
{
count++;
}
~ A (){}
int getValue()
{
static int val=0;
++val;
cout<<"Addres of Value:"<<&val<<endl;
return val;
}
static int getCount()
{
return count;
}
private:
static int count;
};
int A::count=0;
int main()
{
A a;
cout<<a.getValue()<<" "<<a.getCount()<<endl;
cout<<a.getValue()<<" "<<a.getCount()<<endl;
A b;
cout<<b.getValue()<<" "<<b.getCount()<<endl;
system("pause");
return 0;
}