// 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;
}
总结以上是内存溢出为你收集整理的C++11 Auto全部内容,希望文章能够帮你解决C++11 Auto所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)