Right, here is walls_
std::vector<std::shared_ptr<Wall>> walls_;
and here is Wall deriving from WorldObject
1 2 3
|
class Wall : public WorldObject{
//...
};
|
I'll also add that changing the functions to
1 2 3 4 5 6
|
void GridSquare::AddStationaryObject(std::shared_ptr<WorldObject> object){
stationaryObjects_.push_back(object);
}
void GridSquare::AddGridObject(std::shared_ptr<WorldObject> object){
gridObjects_.push_back(object);
}
|
I.e. passing by value instead of reference, gets rid of the errors, but I'm pretty sure this would cause my one shared_ptr to be split into two different shared_ptr's which wouldn't work.
It would also appear that inheritance simply isn't working as I expect it to here. For instance, passing an object of equal inheritance level to the above functions, (where they take it by ref. not value) works just fine, but if the object being passed is further down the inheritance chain, then the C2664 error is thrown. Here is an example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
class WorldObject{
//...
};
class MoveableObject : public WorldObject{
//...
};
class Ball : public MoveableObject{
//...
};
std::vector<std::shared_ptr<WorldObject>> objects;
std::vector<std::shared_ptr<MoveableObject>> moveableObjects;
Ball ball;
objects.push_back(std::make_shared<WorldObject>(ball));
moveableObjects.push_back(objects[0]);
gridsquare::AddWorldObject(moveableObjects[0]); //doesn't work because moveableObjects isn't a world object, it only derives from it. but...
GridSquare::AddWorldObject(objects[0]); //DOES work since objects[0] is a world object, although object[0] is simply a Ball...
|
So in short, I'm pretty upset about this pickiness. Are there any solutions to this, or have I done something wrong?
Edit Number 4: Wow, all that typing and all I had to do was simply type 'const' in the function parameters... Well, at least I learned something