C++11 Auto
// auto.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #include "pch.h" #include #include #include using namespace std; class Foo { public : ?? ?static int get(void) ?? ?{ ?? ??? ?return 0; ?? ?} }; class Bar? { public: ?? ?static const char* get(void) ?? ?{ ?? ??? ?return "0"; ?? ?} }; template void func(void) { ?? ?auto val = A::get(); } int main() { ?? ?auto ?x = 5;?? ??? ??? ??? ??? ?// OK: x==> int? ?? ?auto pi = new auto(1);?? ??? ??? ?// OK: pi==>int* ?? ?const auto *v = &x,u = 6;?? ??? ?//OK: v ==>const int*,u==>const int? ?? ?static auto y = 0.0;?? ??? ??? ?//OK: y ==>double ?? ?// auto int r ; error ?? ?// auto s; error ?? ?int xx = 0; ?? ?auto* a = &xx;?? ?//a==>int*,auto==>int ?? ?auto b = &xx;?? ?//b==>int*,auto==>int* ?? ?auto &c = xx;?? ?//c==>int&,auto==>int ?? ?auto d = c;?? ??? ?//d==>int,auto==>int ?? ?const auto e = xx;?? ?//e==>const int? ?? ?auto f = e;?? ??? ??? ?//f==>int ?? ?const auto& g = xx;?? ??? ?//g==>const int& ?? ?auto& h = g;?? ??? ??? ?//f==>const int& ?? ?//auto limits ?? ?//1.can't be a parameter of a function ?? ?//2.can't be used in a non-static variable member ?? ?//3.can't define an array ?? ?//4.can't infer the template's parameter ?? ?// stl container example ?? ?/* ?? ?map ?? ?map ?? ?for (;it != resMap.end();++it) ?? ?{ ?? ?} ?? ?*/ ?? ?map ?? ?for (auto it=resMap.begin();it != resMap.end();++it) ?? ?{ ?? ?} ?? ?/* ?? ?unordered_multimap ?? ?unordered_multimap ?? ?*/ ?? ?unordered_multimap ?? ?//auto range = map.equal_range(key); ?? ?// a new sample auto simple the function ?? ?func ?? ?func ?? ?return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |