C++对象模型 ch2 构造函数语意学
2011-09-14 21:52
239 查看
1. Programmers new to C++ often have two common misunderstandings:
That a default constructor is synthesized for every class that does not define one
That the compiler-synthesized default constructor provides explicit default initializers for each data member declared within the class
As you have seen, neither of these is true.
2. This apparent anomaly between initialization order and order within the initialization list can lead to the following nasty pitfall
运行结果:
That a default constructor is synthesized for every class that does not define one
That the compiler-synthesized default constructor provides explicit default initializers for each data member declared within the class
As you have seen, neither of these is true.
2. This apparent anomaly between initialization order and order within the initialization list can lead to the following nasty pitfall
>> cat B.CPP #include <iostream> using namespace std; class B { public: int i; int j; B(int v):j(v),i(j){} }; int main() { B b(3); cout << b.i << endl; }
运行结果:
>> ./a.out -4197020
相关文章推荐
- 深入探索C++对象模型之二 --- 构造函数语意学
- 深入探索C++对象模型笔记之四 —— 构造函数语意学 (Copy Constructor的建构操作)
- 深入探索C++对象模型 第二章 构造函数语意学
- 深度探索C++对象模型学习 之 C++构造函数语意学(一)
- C++对象模型学习——构造函数语意学
- 深入探索C++对象模型笔记之五 —— 构造函数语意学 (成员们的初始化队伍 Member Initialization List)
- 【C++对象模型】构造函数语意学之二 拷贝构造函数
- 深度探索C++对象模型 第二章构造函数语意学
- C++对象模型-构造函数语意学
- C++对象模型 第二章 构造函数语意学
- 深入探索C++对象模型:第二章构造函数语意学
- 《深入探索C++对象模型》第二章:构造函数语意学(下)
- 深入探索C++对象模型笔记之三 —— 构造函数语意学 (Default Constructor的建构操作)
- 【C++对象模型】构造函数语意学之二 拷贝构造函数
- 【C++对象模型】构造函数语意学之一 默认构造函数
- 【C++对象模型】构造函数语意学之一 默认构造函数
- 深度探索C++对象模型 之 构造函数语意学
- 【C++对象模型】第二章 构造函数语意学
- c++对象模型笔记之构造函数
- 深入探索C++对象模型:第三章 DATA语意学