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