gpt4 book ai didi

c++ - c++ 中的 decltype() 导致编译错误

转载 作者:搜寻专家 更新时间:2023-10-31 00:57:45 25 4
gpt4 key购买 nike

我是 C++ 新手。在一个教程中,我正在阅读有关 autodecltype 的内容,并尝试了以下操作:

#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 中的关键字

为什么会这样?

最佳答案

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

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

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

关于c++ - c++ 中的 decltype() 导致编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36816724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com