2016-04-23 122 views
2

我是新来的C++。在教程中,我正在读关于autodecltype和尝试以下操作:C++中的decltype()导致编译错误

#include <iostream> 

using namespace std; 

int foo = 0; 
decltype(foo) bar; 
bar = 22; 


int main(){ 
    cout<<foo; 
    cout<<bar; 
    } 

,并在编译时我收到此错误:

tst.cpp.6:1:警告:标识符“decltype”被C++中的关键字11

为什么会发生这种情况?

+1

你明确允许在构建链C++ 11层的功能? – StoryTeller

+1

顺便说一句,这不是一个错误,这是一个警告。差异:错误=错误,编译被中止。警告=某些东西看起来对编译器来说可疑,但它仍然继续编译。 – HolyBlackCat

回答

4

你需要-std=c++11标志(命令行参数)添加到您的编译器:

g++ -std=c++11 tst.cpp -o your_program_name.exe 

更多阅读:Compiling C++11 with g++

相关问题