我在C中的代码编译和正常工作,我想在C++中使用类似的代码:
static const char* aTable[12] = {
[4]="seems",
[6]=" it ",
[8]="works",};
int main(){
printf("%s%s%s", aTable[4],aTable[6],aTable[8]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我把它放在一个.c文件中,并编译gcc它的工作原理.但是,如果我把它放在一个.cpp文件中并用它编译g++,我会得到以下错误:
test_cpp.cpp:5:3: error: expected identifier before numeric constant
test_cpp.cpp:5:4: error: type '<lambda>' with no linkage used to declare function 'void<lambda>::operator()() const' with linkage [-fpermissive]
test_cpp.cpp: In lambda function: test_cpp.cpp:5:5: error: expected '{' before '=' token
test_cpp.cpp: At global scope: test_cpp.cpp:5:5: warning: lambda expressions only available with
-std=c++0x or -std=gnu++0x [enabled by default]
test_cpp.cpp:5:6: …Run Code Online (Sandbox Code Playgroud)