请教个c++语法问题(在android源代码中看到)
是在android的JB代码的init_parser.c文件中:
#define KEYWORD(symbol, flags, nargs, func) \
[ K_##symbol ] = { #symbol, func, nargs + 1, flags, },
struct {
const char *name;
int (*func)(int nargs, char **args);
unsigned char nargs;
unsigned char flags;
} keyword_info[KEYWORD_COUNT] = {
[ K_UNKNOWN ] = { "unknown", 0, 0, 0 }, //这是什么语法?好像和lambda function有关?
#include "keywords.h"
};
其中,K_UNKNOWN是一个枚举类型,KEYWORD_COUNT是枚举类型中的最后一个变量。那些宏定义什么的都不是关键。
于是,我依样画葫芦的写了以下代码,可是用Android.mk编译出错了,,,
enum
{
AA,
BB,
COUNT
};
struct {
int m;
int count;
}aa[COUNT] = {
[ AA ] = { 2, 3 },
[ BB ] = { 5, 3 },
};
target C++: test <= main.cpp
main.cpp: In lambda function:
main.cpp:53:16: error: expected '{' before '=' token
main.cpp: In function 'int main(int, char**)':
main.cpp:53:16: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
main.cpp:53:25: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
main.cpp:53:25: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
main.cpp:53:25: error: no match for 'operator=' in '{(._18)0u} = {2, 3}'
main.cpp:53:25: note: candidate is:
main.cpp:53:14: note: main(int, char**)::<lambda()>& main(int, char**)::<lambda()>::operator=(const main(int, char**)::<lambda()>&)
main.cpp:53:14: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const main(int, char**)::<lambda()>&'
main.cpp: In lambda function:
main.cpp:54:16: error: expected '{' before '=' token
main.cpp: In function 'int main(int, char**)':
main.cpp:54:16: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
main.cpp:54:25: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
main.cpp:54:25: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
main.cpp:54:25: error: no match for 'operator=' in '{(._18)1u} = {5, 3}'
main.cpp:54:25: note: candidate is:
main.cpp:54:14: note: main(int, char**)::<lambda()>& main(int, char**)::<lambda()>::operator=(const main(int, char**)::<lambda()>&)
main.cpp:54:14: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const main(int, char**)::<lambda()>&'
make: *** [test/main.o] Error 1