#include<iostream>
using namespace std;
class A;
A* a1 = NULL;
struct C
{
int C1;
int C2;
};
class A
{
public:
A()
{
a = 1;
cc.C1 = 3;
cc.C2 = 4;
}
private:
int a;
C cc;
public:
static int b;
void printA(){cout<<"a: "<<a<<endl;
//b ++;
}
static void printB(){
//cout<<"a"<<a<<endl;
//cout<<"C1"<<c.C1<<endl;//报错为“.C1”的左边必须有类/结构/联合
cout<<"C1: "<<a1->cc.C1<<endl;
cout<<"b"<<b<<endl;
}
};
int A::b = 5; //没有这一句执行不了!FUCK
class AA
{
public:
static int a;
static void printAA()
{
a = 5;
cout<<"a: "<<a<<endl;
}
};
int main()
{
a1 = new A();
a1->printA();
A::printB();
delete a1;
AA a2;
//AA::printAA();
//cout<<AA::a<<endl; //无法解析的外部符号 "public: static int AA::a" (?a@AA@@2HA)
return 0;
}
1.static 引用非STATIC的方法,通过类对象进行引用!
2.static变量要不要声明初始化!