cjurjiu
cjurjiu

Reputation: 1798

Eclipse C++ std::vector methods invalid parameters errors

I am working on an Android application that uses OpenCV 2.4.9 and NDKr9 as dependecies. I also use Eclipse 4.4 Luna as the IDE, with CDT plugin 8.4 installed.

Whenever I'm trying to use the methods std::vector.at(int), or the "[]" method, i get weird errors. For instance, consider the code:

#include <vector>
.........................

struct CustomStruct {
int level;
Point firstPoint, secondPoint, middlePoint;
};
.........................

int maxElemNr = 10;
std::vector<CustomStruct > customStructVector(maxElemNr);
.........................

for(int i=0;i<customStructVector.size();i++){
            if(customStructVector.at(i).level == 0){

            }
        }

At customStructVector.at(i) Eclipse tells me the following:

Invalid arguments ' Candidates are: ResultWithEvidence & at(?) const ResultWithEvidence & at(?)'

If I want to use the "[]" operator, instead of the "at(index)" method, i get the following: resultWithEvidenceVector[i].level tells me that the field level is not found.

I am by no means an expert C/C++ coder, and I am rather new at working with the NDK. Coming from a Java background, I was expecting to get an object of type CustomStruct when calling either customStructVector.at(i) or customStructVector[i], such that I could then simply access the field level on my object, to read its value.

Also, declaring my vector as

int maxElemNr = 10;
std::vector<CustomStruct> customStructVector;
customStructVector.reserve(maxElemNr);

I get:

Invalid arguments ' Candidates are: void reserve(?) '

I have searched for answers, and came with the theory that eclipse might not use the c++11 version of the std library?

I've read about the vector class from here. Also, this issue closely resembles the question asked here.

Will provide more info about my environment and such, if needed. Would like to solve this, as it's quite a blocker for my project as of now..

What am I doing wrong? I had no problems compiling and running the code previously to using the std::vector class.

LE: apparently the workaround &(resultWithEvidenceVector.data()+i)->level is recognized by the editor, and the code compiles. Would still like to use the std::vector as it is supposed to be used though.

Upvotes: 0

Views: 783

Answers (1)

autodev101
autodev101

Reputation: 60

I had the same problem. It works in Visual Studio compiler but when i try to access vector element i get exactly the same error.

However it seems that if you don't use 'at' then it works for example customStructVector.at(i) use customStructVector(i),

It is strange. I didn't test it in detail. Please note that if you have vector you have to cast the result in order to access the type members.

Regards

Upvotes: 1

Related Questions