【发布时间】:2019-09-23 22:23:53
【问题描述】:
我正在尝试查找变量的类型。在 stackoverflow 中提到 decltype() 用于此目的。但是当我尝试使用它时,它会抛出我在标题中提到的错误。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x = 4;
cout << decltype(x);
return 0;
}
我期待int,但它显示为错误。 error: expected primary-expression before 'decltype'
【问题讨论】:
-
你也不能
cout << int;。 -
你的意思是
typeid(x).name()。 -
@chris 所以你的意思是 decltype() 不输出字符串。谢谢。
-
@LogicStuff 是的,我用过。但是在stackoverflow中的一些地方他们提到decltype比typeid().name更好