【发布时间】:2018-05-28 04:23:17
【问题描述】:
// g++ 7.3
template<typename T>
struct td;
int main()
{
int a = 1;
td<decltype((const int)a)> t1;
td<decltype((const int)1)> t2;
return 0;
}
下面是编译的输出:
错误:聚合 ‘td<int> t1’ 的类型不完整,无法定义
错误:聚合 ‘td<const int> t2’ 的类型不完整,无法定义
那么,为什么decltype((const int)a) 和decltype((const int)1) 的类型不同呢?
【问题讨论】:
-
请以文本形式而不是图像形式发布编译器消息。文本内容易于搜索。
-
它也易于访问。
-
以防万一有人不知道:OP 正在使用“类型显示”技巧通过编译器错误消息显示类型。
-
我的实验表明 GCC 7.3 和 8.1 的行为不同。 godbolt.org/g/cjNLAF
标签: c++ type-conversion decltype