侯捷C++11课程笔记—第三次课
侯捷C++11课程笔记
第三课:Spaces in Template Expressions,nullptr and std::nullptr_t,Automatic Type Deduction with auto
1.Spaces in Template Expressions
vector<list<int> >; //OK in each C++ version
vector<list<int>>; //OK since C++11
2.nullptr and std::nullptr_t
C++11中针对空指针,我们用nullptr,之前是使用NULL或者0.
typedef decltype(nullptr) nullptr_t;
3.Automatic Type Deduction with auto
auto i = 42; //i has type int
double f();
auto d = f(); //d has type double
当type很长或者很复杂的时候我们用auto
vector<string> v;
vector<string>::iterator it = v.begin();
auto it = v.begin();
auto s = [](int x)->bool{ //s has the type of lambda
.........,
};