android - 使用 Android NDK 时,Eclipse 编辑器将无法识别 C++ 模板类型

标签 android c++ eclipse android-ndk eclipse-cdt

我正在尝试使用 NDK 和 Eclipse CDT 将以下简单的 C++ 代码编译为原生 Android 代码:

#include <vector>

using namespace std;

class Pt {
public:
  Pt(int _x, int _y);
  int x;
  int y;
};

Pt::Pt(int _x, int _y){
x = _x;
y = _y;
}

void test(){
  std::vector<Pt> pts;
  pts.push_back(Pt(2,3));
  int i = pts[0].x; //error here
}

我可以从命令行使用 ndk-build.cmd 毫无问题地编译代码,我什至可以从 Eclipse 中编译它。问题是在最后一行(此处有//error 注释),Eclipse 编辑器报告以下错误:

Field 'x' could not be resolved

可能的解决方案是:

  • 像这样写 pts[0].x:int i = ((Pt)pts[0]).x;
  • 使用 var: Pt apt = pts[0]; int i = apt.x;(令人惊讶的是,这有效)

我花了将近 2 天的时间尝试使用自定义路径设置 Eclipse 以包含文件、使用索引器、升级到最新的 NDK 以及我能想到的一切。问题依然存在。这个问题显然出现在每个采用参数化类型的类中(不仅是 vector )。 尽管 Eclipse 确实编译了代码,但报告此错误的事实导致 Android 项目被标记为“有错误”,从而无法将其作为一个整体运行。

非常感谢任何帮助, 谢谢

最佳答案

可能是this可以帮助你,你必须在项目属性中包含正确的 STL header 。

关于android - 使用 Android NDK 时,Eclipse 编辑器将无法识别 C++ 模板类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22330773/

相关文章:

android - 任务 ':app:mergeDebugResources'的Jenkins执行失败,找不到文件

android - 如何在 Gradle 构建脚本(Android)中定义和使用常量?

c++ - 如何在运行时确定 vector 大小?

php - Eclipse Helios - 添加 PHP 可执行文件时出现问题

android - 如何让 Eclipse 手动连接到 Android 模拟器?

java - 套接字只能发送一次,并且 Textview 不会从服务器收集信息

Android共享元素过渡

c++ - 简单程序省略的第一个字符

c++ - 用 0xDD 或 0xCC 或 0xFD 或 0xCD 检查指针好吗?

android - 当我安装我的 apk 时,我得到了项目中每个类的图标