0

I am trying to compile the following simple C++ code as native Android code using the NDK and the Eclipse CDT:

#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
}

I can compile the code with no problem with the ndk-build.cmd from the command line, and I can even compile it from within Eclipse. The problem is that at the last line (where there is the //error here comment), the Eclipse editor reports the following error:

Field 'x' could not be resolved

Possible solutions are:

  • write the pts[0].x like that: int i = ((Pt)pts[0]).x;
  • use var: Pt apt = pts[0]; int i = apt.x; (amazingly, this works)

I have spent almost 2 days trying to setup eclipse with custom paths to include files, play with the indexer, upgrade to latest NDK and everything else i can imagine. The problem remains. This problem obviously appears with every class that takes a parameterized type (not only with vector). Although Eclipse does compile the code, the fact that reports this error causes the Android project to be marked as 'having errors', thus making it impossible to Run it as a whole.

Any help is much appreciated, Thanks

user3406992
  • 113
  • 2
  • 8

1 Answers1

1

May be this can help you, you have to include proper headers for STL in project properties.

Community
  • 1
  • 1
Yuvi
  • 1,344
  • 4
  • 24
  • 46
  • I have done all that; these were needed for std type to get recognized (e.g. vector). But the problem here is that the template 'return types' are not recognized in the editor. Notice that Eclipse does not say that 'vector' is unrecognized; it rather says that 'x' cannot be resolved (and this only when the specific syntax is used). – user3406992 Mar 12 '14 at 08:04