?????????????? auto
????auto???????????????????????????????????????????????????auto?????????????????????????????;
????auto????????????????????????????????????????????Ч???????????;
???????????auto?????????????????????????????????????????ж????????????
????auto a; // ????auto???????????????????????????????г????????????????a??????
????auto i = 1;
????auto d = 1.0;
????auto str = "Hello World"
????auto ch = 'A'
????auto??????????????????????????????????η???????????
????int x = 5;
????int & y = x;
????auot z = y ;
????// z ?int
????auto & z = y;
????// z??????? int&
??????????????????????????????????????*???η???Ч?????????
????int  *px = &x;
????auto py = px;
????auto*py = px;
???????????
????const int *px = &x;
????auto py = px;
????//py??????? const int *
????const auto py = px ;
????//py???????const int *
??????????? decltype
????decltype??????е???auto????????????auto??????????????????????????????decltype???????????????????????????????
#include
int main() {
int x = 5;
decltype(x) y = x;
//???? auto y = x;
const std::vector v(1);
auto a = v[0];
// a has type int
decltype(v[1]) b = 1;
// b has type const int&?? the return type of
// std::vector::operator[](size_type) const
auto c = 0;
// c has type int
auto d = c;
// d has type int
decltype(c) e;
// e has type int?? the type of the entity named by c
decltype((c)) f = c;
// f has type int&?? because (c) is an lvalue
decltype(0) g;
// g has type int?? because 0 is an rvalue
}
?????????????STL?е????????д?????????????????????
????????????????? Trailing return type
????C++11???????????
???????磺
????int adding_func(int lhs?? int rhs);
????????д???
????auto adding_func(int lhs?? int rhs) -> int
????auto?????λ??????????????????漲?壻
??????????????????????????????????????????
??????????????????У????????????????????????????????????
????template
????auto adding_func(const Lhs &lhs?? const Rhs &rhs) -> decltype(lhs+rhs)
????{return lhs + rhs;}
????cout << adding_func<double??int>(dv??iv) << endl;
????auto?????λ????????????????????????????У?????????????????
????????auto?λ??????????decltype????????
????decltype(lhs+rhs) adding_func(const Lhs &lhs?? const Rhs &rhs)
????????д?????????????????????????lhs??rhs???????仹δ??????
?????????????д????????????
????decltype( (*(Lhs*)0) + (*(Rhs*)0) ) adding_func(const Lhs &lhs?? const Rhs &rhs)
???????????????????????????auto?λ?????????????
??????????? nullptr
???????????(nullptr)???????????????????????????????????????????????????????????????????????NULL?????????????????????????????????NULL?????????????????0?????nullptr??C++11?????????????????????????
????nullptr???κ?????????????????????????????????????????????????????????????bool??????false?????????????????ε?????????????
????????nullptr???????????C++??NULL???????????
voidF(int a){
cout<<a<<endl;
}
voidF(int*p){
assert(p != NULL);
cout<< p <<endl;
}
int main(){
int*p = nullptr;
int*q = NULL;
bool equal = ( p == q );
// equal????true?????p??q????????
int a = nullptr;
// ????????nullptr????????int
F(0);
// ??C++98?б????????ж????????C++11?е???F??int??
F(nullptr);
return 0;
}
??????????? range-based for loop
????C++11?????for????????????????????????????????????????????????
????int my_array[5] = {1?? 2?? 3?? 4?? 5};
????// double the value of each element in my_array:
????for (int &x : my_array) {
????x *= 2;
????}
?????????????????auto???????
????for (auto &x : my_array) {
????x *= 2;
????}
????????и???????????????auto???????????????????
????map<string??int> map;
????map.insert<make_pair<>("ss"??1);
????for(auto &x : my_map)
????{
????cout << x.first << "/" << x.second;
????}