4

在为 iOS 项目编译我的 C++ 时,一切正常。但是,我在 Android 上遇到了困难。

我的 Application.mk 内容如下:

APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-11
APP_STL := stlport_shared

所有 LOCAL_SRC_FILES 都已定义。

当我尝试构建我的模块时,我收到以下编译器错误:

jni/Game.hpp: In member function 'const std::pair<pos, Obj*>* MyEnumerator::next()':
jni/Game.hpp:126:23: error: expected type-specifier
jni/Game.hpp:126:23: error: cannot convert 'int*' to 'std::pair<pos, Obj*>*' in assignment
jni/Game.hpp:126:23: error: expected ';'

上面提到的代码行是:

this->ptr = new pair<pos, Obj*>::pair(it->first, it->second);

在这里,ptr是类型pair<pos, Obj*>*并且pos是结构。我已经声明了using std::pair;

关于什么是错误的以及尝试什么的任何提示?

4

1 回答 1

4

尝试将行更改为:

this->ptr = new std::pair<pos, Obj*>(it->first, it->second);

恕我直言,丢失 using 指令并使用完全限定名称。它干净、精确,并且不允许命名冲突。如果你必须使用它们,不要在头文件中使用它们,只在你的实现文件中使用它们。

于 2012-12-17T03:04:31.823 回答