"Simple" question put short:
Why exactly does
JNIEnv *g_env = NULL;
(*g_env)->ExceptionDescribe(g_env);
Run Code Online (Sandbox Code Playgroud)
compile in gcc (C)
but not in g++ (C++)
error: base operand of ‘->’ has non-pointer type ‘JNIEnv’ {aka ‘JNIEnv_’}
Run Code Online (Sandbox Code Playgroud)
As I am working mainly with C++ I don't see why it should compile. As stated by the error, dereferencing the pointer will yield a "variable" and not a pointer anymore. I.e.: in C++ it would be either
g_env->ExceptionDescribe
Run Code Online (Sandbox Code Playgroud)
or
(*g_env).ExceptionDescribe
Run Code Online (Sandbox Code Playgroud)
as its not JNIEnv **
给出以下结构:
struct FieldNo
{
FieldNo() : a('0'), b('0') {}
FieldNo(char a_, char b_) : a(a_), b(_b) {}
// copy construction and assigment not allowed
FieldNo(const FieldNo& other) = delete;
FieldNo& operator=(const FieldNo& other) = delete;
// move construction and assignment ok
FieldNo(FieldNo&& other) = default;
FieldNo& operator=(FieldNo&& other) = default;
char a;
char b;
};
enum class Members : int8_t
{
FOO,
BAR
};
Run Code Online (Sandbox Code Playgroud)
我正在FieldNo用作Memberstd :: unordered_map的键和值。省略哈希创建函数的代码,我的地图定义如下:
typedef std::unordered_map<FieldNo, Members, FieldNoHasher> MyMapT;
Run Code Online (Sandbox Code Playgroud)
后来我用下面的方法初始化并返回到调用者
const MyMapT& map() …Run Code Online (Sandbox Code Playgroud)