我正在尝试查找变量的类型。在 stackoverflow 中提到了decltype()用于此目的。但是当我尝试使用它时,它会抛出我在标题中提到的错误。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x = 4;
cout << decltype(x);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我预料到了int,但它显示为错误。error: expected primary-expression before 'decltype'