Gotchas in the C++ programing language
2007-01-29 20:47
429 查看
Initializer lists
In C++, it is the order of the class inheritance and of the member variables that determine the initialization order, not the order of an initializer list:#include <iostream>
class CSomeClass
{
public:
CSomeClass(int n)
{
std::cout << "CSomeClass constructor with value ";
std::cout << n << std::endl;
}
};
class CSomeOtherClass
{
public:
CSomeOtherClass() //In this example, despite the list order,
: obj2(2), obj1(1) //obj1 will be initialized before obj2.
{
//Do nothing.
}
private:
CSomeClass obj1;
CSomeClass obj2;
};
int main(void)
{
CSomeOtherClass obj;
return 0;
}
相关文章推荐
- (轉貼) Evolving a language in and for the real world C++ 1991-2006 (中文翻譯版) (By Bjarne Stroustrup) (C/C++)
- c++程序设计语言(the c++ programing language) 目录
- Bjarne新文章《Evolving a language in and for the real world: C++ 1991-2006》的读后感
- The environment of C++ Programing in Linux
- (轉貼) Evolving a language in and for the real world C++ 1991-2006 (英文版) (by Bjarne Stroustrup) (C/C++)
- The C++ Programming Language 第五章
- 《The C++ Programming Language》摘抄与总结——关于
- In which of the following does a C++ developer use the placement new syntax to make new allocate an
- The C++ Programming Language 读书笔记(一)
- Question 43: Which of the following define valid string constants in C++?
- The UNO C++ Language
- The C programing language 第四章,课后题
- how to deal with the situation that the language support option disappears in linux ubuntu
- The pointer in C++ /CLI
- How to implement the similar mechanism with Java final in c++?
- The C++ Programming Language(二)
- Errata for The C++ Programming Language(SE)(涵盖影印版至今的所有已知错误)
- The C programing language 第二章课后题
- The C++ In-Depth Series
- vscode 中 安装插件 vetur 之后报错 The Vue Language Server server crashed 5 times in the last 3 minutes. The s