C++11之decltype
来源:互联网 发布:只有我知 在线观看 编辑:程序博客网 时间:2024/06/05 07:42
使用场景
3、函数返回值
注意
1、decltype两个括号返回变量引用类型
在C++中经常要用到很长的变量名,如果已经有变量和你将使用的变量是一个类型,即可使用decltype关键字
来申明一样的类型变量。
decltype原理返回现有变量类型,decltype是一个关键字,而不是一个函数,这有啥区别呢?decltype在编译阶段返回变量类
型,而不是在运行阶段传递不同变量返回不同值。
decltype使用范例
1、复杂已知变量类型map<string, vector<string>> str_map;decltype(str_map) str_map_new;2、表达式返回值类型
int a, b;decltype(a + b) a;
3、函数返回值
int foo(int i) { return i;}double foo(double d) { return d;}template<typename T>auto getNum(T t)->decltype(foo(t)) { return foo(t);}
注意
1、decltype两个括号返回变量引用类型
int i;decltype((i)) r = i;decltype(i) a;2、auto和decltype配合使用可以实现不同返回类型
1 1
- C++11之decltype
- C++11之decltype
- C++11之decltype
- C语言11中的auto和decltype
- C++11 新特性之 decltype关键字
- c++ 11 游记 之 decltype constexpr
- C++11系列学习之五-------decltype
- C++11 新特性 之 decltype
- C++11之auto、decltype关键字
- C++11新特性之auto&decltype
- C++Primer学习之三auto和decltype
- 类型推导之decltype
- C++11 理解 (一) 之 auto与decltype的运用
- [C++] decltype类型指示符
- Modern C++(三)decltype关键字
- C++ 11 auto & decltype
- 【c++11】 decltype
- C++ 11 auto & decltype
- JavaSE 线程同步之synchronized
- C++封装socket
- do while(0)的另一个用途:消除goto语句。
- jQuery实现的全选、反选和不选功能
- ubuntu 13.10 eclipse 汉化
- C++11之decltype
- cglib 动态代理
- ZOJ 3640 Help Me Escape(概率dp)
- 排序(三) 堆排序
- 关于坚持
- iOS7 UIKit动力学-碰撞特性UICollisionBehavior 下
- uitableview中的cellforrow方法里 修改button title
- Cocos2d-x运行时错误:Cocos2d: Get data from file(xxx.xxx) failed!
- 小谈Scrum敏捷开发流程