Inside of a class called Castle I have the following 2 functions:
vector<Location> Castle::getMoves(Location*** squares, Location* loc){
int row = loc->getRow();
int col = loc->getCol();
vector<Location> moves;
//problem is here!
getVerticalMoves(squares, &moves, row, col);
return moves;
}
void Castle::getVerticalMoves(Location*** squares, vector<Location*> * moves, int row, int col){
//need to do something here, but can't call the function!
}
When I try to compile, I get an error that looks like this:
model/src/Castle.cpp: In member function ‘std::vector<Location> Castle::getMoves(Location***, Location*)’:
model/src/Castle.cpp:26:44: error: no matching function for call to ‘Castle::getVerticalMoves(Location***&, std::vector<Location>*, int&, int&)’
model/inc/Castle.h:38:8: note: candidate is: void Castle::getVerticalMoves(Location***, std::vector<Location*>*, int, int)
make: *** [model/obj/Castle.o] Error 1
I do not understand why this error is appearing. Why does it say that I am passing it references?
Do you want a vector of
Locations? Or do you want a vector of pointers toLocations? You need to pick one and stick with it.The reason it shows a reference is because if it showed just the value, that would suggest that you could not call a function that takes a reference, since a reference can appear on the left side of an equals sign and a value cannot. What you passed to the function can appear on the left side of an equals sign, so leaving off the & would make the error message less informative. (Suggesting perhaps your mistake was to pass a value where a modifiable reference was required.)
Consider:
So when you pass an lvalue (something that can appear on the left side of an equal sign), you really are calling the function with a reference — something more powerful than a mere value.