转载自auto and delctype(auto) type deduction example
一个让编译器输出变量类型的小技巧:
- 定义如下结构体
template <typename>
struct TD;
- 然后使用如下方法查看变量
variable
的变量类型
TD<decltype(variable)>();
解释
TD<…> 是一个不完整的类型, 编译器会报错,输出如下信息:
error: invalid use of incomplete type struct TD<variable_type>
variable_type就是你想要知道的变量类型