我有一些代码:
std::array<JNINativeMethod, 26> methods = {
{ "nativeCreate", "(Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) },
{ "nativeDestroy", "(J)V", reinterpret_cast<void*>(&nativeDestroy) },
...
{ "nativeToggleDebug", "(J)V", reinterpret_cast<void*>(&nativeToggleDebug) }}
};
我正在尝试使用 Android NDKs clang 3.4 编译器进行编译。
但是,该代码给了我这个错误:
jni/JNI.cpp:252:9: error: excess elements in struct initializer
{ "nativeDestroy", "(J)V", reinterpret_cast<void*>(&nativeDestroy) },
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
除非我添加另一组大括号:
std::array<JNINativeMethod, 26> methods = {{
{ "nativeCreate", "(Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) },
{ "nativeDestroy", "(J)V", reinterpret_cast<void*>(&nativeDestroy) },
...
{ "nativeToggleDebug", "(J)V", reinterpret_cast<void*>(&nativeToggleDebug) }}
}};
这对我来说似乎很奇怪,但在找到有关 Visual C++ 的讨论后:http: //social.msdn.microsoft.com/forums/vstudio/en-US/e5ad8fa5-c9e8-4328-a7fa-af7a47ce2492/initialising-a-stdarray-结构的
我想知道这是否是不正确的 C++11 语法,或者只是 clang 3.4 中的一个缺陷。
它是否与使用带有 clang 的初始化列表初始化简单结构中提到的错误有关