我曾经编译以下代码:
const std::map<std::string, bool> pending_achs = The result from this method std::map<std::string, bool> get_pending_ach_modifications() const { return stuff; };
和
for (auto const& [key, val] : pending_achs) {
if(val) {
// Stuff
} else {
// Stuff
}
}
我认为在阅读this answer之后,该代码才是有效的代码。
我正在使用以下命令构建代码:
g++ -std=c++17 -g \
`pkg-config --cflags gtk+-3.0` \
-rdynamic -export-dynamic -pthread -Wall \
SAM.Picker/*.cpp \
common/*.cpp \
-L$SCRIPTPATH/bin \
-o $SCRIPTPATH/bin/samrewritten \
`pkg-config --libs gtk+-3.0` \
-lpthread -lgmodule-2.0 -lsteam_api -lcurl
但是出现以下错误:
SAM.Picker/gtk_callbacks.cpp: In function ‘void on_store_button_clicked()’:
SAM.Picker/gtk_callbacks.cpp:42:26: error: expected unqualified-id before ‘[’ token
for (auto const& [key, val] : pending_achs) {
^
SAM.Picker/gtk_callbacks.cpp:42:26: error: expected ‘;’ before ‘[’ token
SAM.Picker/gtk_callbacks.cpp:42:27: error: ‘key’ was not declared in this scope
for (auto const& [key, val] : pending_achs) {
^~~
SAM.Picker/gtk_callbacks.cpp:42:32: error: ‘val’ was not declared in this scope
for (auto const& [key, val] : pending_achs) {
^~~
SAM.Picker/gtk_callbacks.cpp: In lambda function:
SAM.Picker/gtk_callbacks.cpp:42:37: error: expected ‘{’ before ‘:’ token
for (auto const& [key, val] : pending_achs) {
^
SAM.Picker/gtk_callbacks.cpp: In function ‘void on_store_button_clicked()’:
SAM.Picker/gtk_callbacks.cpp:42:37: error: expected ‘;’ before ‘:’ token
SAM.Picker/gtk_callbacks.cpp:42:37: error: expected primary-expression before ‘:’ token
SAM.Picker/gtk_callbacks.cpp:42:37: error: expected ‘)’ before ‘:’ token
SAM.Picker/gtk_callbacks.cpp:42:37: error: expected primary-expression before ‘:’ token
是的,错误之前的行以分号结束。
我很确定这确实很愚蠢,最终我将删除这个问题,但是我已经坚持了一段时间,我真的很乐意提供一些帮助。
谢谢大家
编辑:我的GCC版本:
[name@name-pc ~]$ g++ -v
Utilisation des specs internes.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/lto-wrapper
Cible : x86_64-pc-linux-gnu
Configuré avec: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto
Modèle de thread: posix
gcc version 8.2.1 20180831 (GCC)
答案 0 :(得分:0)
好的,我发现了。我用Flatpak安装了Visual Studio Code。每次我尝试编译时,都是在IDE中使用GCC 6.4。
很抱歉浪费大家的时间。我仍然会放弃这个话题,因为它也可以帮助失去的灵魂。