C++ Primer 4th Edition
01. initialization
int ival(1024); // direct-initialization !!
int ival = 1024; //
copy-initialization
02. EOF: Windows -- ctrl+z Unix/MacOS -- ctrl+d
03. manipulator: std::endl
04. sizeof(wchar_t) = 4
05. 对象 = 有类型的内存区域
06. 文件中全局作用域里定义的变量:非const变量,可见性默认是extern的;const变量,可见性默认是当前文件的;
07. header guard in header files
#ifndef ***
#define ***
// related code
#endif
08. Pay attention to: buffer overflow; memory leak;
09. vector<int>::size_type index = 0;
10. iterator: if(ivec.empty())ivec.begin() equal to ivec.end();else ivec.begin() points to the ivec[0], ivec.end() point to 末端元素的下一个。
11. const_iterator
12. 任何改变vector长度的操作都会使已存在的iterator失效。例如,在调用push_back之后,就不能再信赖指向vector的iterator的值了。
13. const修饰符 置于类型前和后是等价的,即
const int == int const , 因此typedef也便于理解了,
typedef string *pstring;
const pstring cstr == pstring const cstr == string *const cstr
14. 只有在必要时才使用后置自增自减操作符。(后置会导致额外的编译器操作)
15. *iter++ == *(iter++) == *iter;iter++;
16. 一旦删除来指针所指向的对象,立即将指针置为0。 delete p; p=0;
17. Preprocessor: __FILE__ __LINE__ __TIME__ __DATE__
18. !!!!
void func(const int i){} //are the same
void func(int i){} //error: redefines func(int)
19. 标准库使用的技术启发而得:传递数组的第一个元素的指针和最后一个元素的下一个位置的指针
20. 函数,引用返回左值
char &get_val(string &str, size_t index) {
return str[index];
}
int main() {
string s("abcdefg");
get_val(s, 0) = 'A';
return 0;
}
如果不希望返回的引用被修改,返回值应该声明为const,如 const char &get_val(...
21. inline is only a suggestion for a compiler, and the definition of an inline function should be placed in the header file
22. 类成员函数的行参表后的const修饰符,修饰来成员函数中的隐藏形参(this),说明了函数的行为对于调用对象(*this)是const的。
23. 函数指针的声明由其返回类型以及参数表决定。
bool (*pf)(const string &, const string &);
typedef bool (*PF)(const string &, const string &);
or
typedef int FUNCTYPE(int, int);
typedef FUNCTYPE *PF;
99.
原文链接: https://www.cnblogs.com/soulnearby/archive/2011/04/19/2020490.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/24237
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!