10??C++??????????????
???????????? ???????[ 2015/1/5 11:16:38 ] ????????C++ net
?????????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();
??????????????????г??????????????????????????????????????????????????е??????????????δ???
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11