#include<iostream>
using namespace std;
/*--------------------static 学习-------*/
int x=100;
class withStatic
{
int i;
static int x;
static int y;
public:
void print() const {
cout<<"x= : "<<x<<endl;
cout<<"y= : "<<y<<endl;
}
static int incr()
{
return ++x;
//return ++i;---------3,error.只能访问静态数据成员,无this指针
}
};
int withStatic::x =1;
int withStatic::y =x+1;
class outer
{
class inner
{
static int i;// 2,ok.嵌套类可以有静态函数
};
};
void f()
{
class Local
{
/*static int i; --------------- 1,error.不能有静态函数*/
};
}
int main()
{
withStatic ws;
ws.print ();
cout<<x<<endl;
return 0;
}