- 论坛徽章:
- 0
|
本帖最后由 Moon_Bird 于 2012-03-31 20:27 编辑
- #include <iostream>
- using namespace std;
- class ClassA {
- public:
- ClassA(): {
- cout << "ClassA Constructor!" << endl;
- }
- void Func() {
- cout << "ClassA Func() Called! Num:" << m_nNum << endl;
- }
- int m_nNum;
- };
- class ClassB {
- public:
- ClassB() {
- cout << "ClassB Constructor! " << endl;
- s_A.Func();
- }
- protected:
- static ClassA s_A;
- };
- ClassB TestClass; //在初始化B内的静态成员之前就先定义了这个对象
- ClassA ClassB::s_A;
- int main(int argc, char *argv[])
- {
- system( "PAUSE ");
- return 0;
- }
复制代码 运行之后,输出结果是这样的:
ClassB Constructor!
ClassA Func() Called! Num: 0
ClassA Constructor!
有哪位大神能解释下为什么会以这样的顺序输出,而且能编译通过? |
|