?????????unsigned?????????0x7??
????????????????ù???????

 

#include <iostream>
using namespace std;
class A
{
public:
A() { cout << "A's Constructor Called " << endl;  }
};
class B
{
static A a;
public:
B() { cout << "B's Constructor Called " << endl; }
};
int main()
{
B b;
return 0;
}

 

?????????
????B's Constructor Called
?????????????????????????B???????????е???A???????????????????????????????????????ж??塣???????????????????????????????????????塣
????????????????????徲????????a?????????????????????????????????????????

 

#include <iostream>
using namespace std;
class A
{
int x;
public:
A() { cout << "A's constructor called " << endl;  }
};
class B
{
static A a;
public:
B() { cout << "B's constructor called " << endl; }
static A getA() { return a; }
};
int main()
{
B b;
A a = b.getA();
return 0;
}

 

?????????
????Compiler Error: undefined reference to `B::a
??????????????a????壬?????????????????????У?
??????????A????????????????x??????B?е?aδ??????????????г??????????????A??

 

#include <iostream>
using namespace std;
class A
{
int x;
public:
A() { cout << "A's constructor called " << endl;  }
};
class B
{
static A a;
public:
B() { cout << "B's constructor called " << endl; }
static A getA() { return a; }
};
A B::a;  // definition of a
int main()
{
B b1?? b2?? b3;
A a = b1.getA();
return 0;
}

 

?????????
????A's constructor called
????B's constructor called
????B's constructor called
????B's constructor called
???????????????B???????3?Σ??????????A?????????Σ???????????????????ж????????????????????????????????????????????????????????????????????????????????κ?????????????????????a??
????int main()
????{
????// static member 'a' is accessed without any object of B
????A a = B::getA();
????return 0;
????}
?????????

 

A's constructor called
union????
#include <stdio.h>
union
{
int i;
char x[2];
}a;
int main()
{
a.x[0] = 10;
a.x[1] = 1;
printf("%d"??a.i);
return 0;
}

 

?????????266???????????????????????union????????????г????????????????Union???С?????????б????????????????????????????????????????
?????????????????????
????class A {
????public:
????int m;
????void print() {  cout << "A ";  }
????};
????A *pa = 0;
????pa->print();
??????????????????????????????????????????????
????void print(A *this) {  cout << "A ";  }
????A *pa = 0;
????print_A();
??????????????????г??????????????????????????????????????????????????е??????????????δ???