Troubles using vector of stuct...
Nov 2, 2009 at 11:32am UTC
Hi,
I am trying to set the property of an object. The property is a std::vector of type struct...
1 2 3 4 5 6 7
void Vetor::setwaypoints(vector<waypoint> wp) {
waypoints = wp;
}
vector<waypoint> Vetor::getwaypoints() {
return waypoints;
}
1 2
void setwaypoints(vector<waypoint> wp);
vector<waypoint> getwaypoints();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Vetor v1, v2;
waypoint wp;
vector<waypoint> waypoints;
for (int i = 0; i < lines; i++) { // Especifica waypoints para v1
for (int j = 0; j < cols; j++) {
wp.line = i;
wp.col = j;
wp.index = idx;
waypoints.push_back(wp);
cout << "index: " << waypoints[idx].index << " line: " << waypoints[idx].line << " col: " << waypoints[idx].col << endl;
idx++;
}
}
v1.setwaypoints(waypoints); // The error is in this line (217)
I am getting this error messages:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/cristiano/NetBeansProjects/gpac nov 01 am'
/usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/gpac_nov_01_am
make[2]: Entering directory `/home/cristiano/NetBeansProjects/gpac nov 01 am'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/Process.o.d
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/Process.o.d -o build/Debug/GNU-Linux-x86/Process.o Process.cpp
Process.cpp: In member function 'void Process::CheckAsymmetricVectorsAlternative(Gpa&)' :
Process.cpp:217: error: no matching function for call to 'Vetor::setwaypoints(std::vector<Process::waypoint, std::allocator<Process::waypoint> >&)'
Vetor.h:34: note: candidates are: void Vetor::setwaypoints(std::vector<waypoint, std::allocator<waypoint> >)
make[2]: *** [build/Debug/GNU-Linux-x86/Process.o] Error 1
make[2]: Leaving directory `/home/cristiano/NetBeansProjects/gpac nov 01 am'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/cristiano/NetBeansProjects/gpac nov 01 am'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 690ms)
Some one have an idea of the error I am making?
Last edited on Nov 2, 2009 at 11:36am UTC
Nov 2, 2009 at 11:58am UTC
What you've posted looks ok. Can you post the declaration of Vector::setwaypoints (from the header file).
Nov 2, 2009 at 12:51pm UTC
Looks like a namespace problem.
Line 9 of error says Process::waypoint, line 10 does not have the namespace.
By any chance have you forward declared waypoint somewhere? If so, did you forward declare it in
the right namespace?
Nov 2, 2009 at 12:58pm UTC
kbw,
declaration of Vector::setwaypoints (from the header file) is in the second box of code above. ok?
Is there another thing I can post for help?
Nov 2, 2009 at 1:17pm UTC
jsmith is right. You should declare the members as:
1 2
void setwaypoints(std::vector<waypoint> wp);
std::vector<waypoint> getwaypoints();
In fact, I'd recomend (again) not to use
using namespace std;
ata all.
Nov 2, 2009 at 5:56pm UTC
Is there another thing I can post for help?
Yes, a more complete example. Where was idx defined and initialized? Not much can be learned by looking at small snips of code. You could have made mistakes while selectively copying and pasting information. It is pretty difficult to help with compiler errors with this type of post unless it is something blatantly obvious. Sometimes it is better to just grab a colleague that is near you who can stare at the entire example with you and wade through the messages.
Topic archived. No new replies allowed.