I recently stated using pointers in a program and when I try the following, I am given this error.
stored_points.push_back(new Point(anchor_y,anchor_x,last_direction));
error C2664: ‘void std::vector<_Ty>::push_back(_Ty &&)’ : cannot convert parameter 1 from ‘Point *’ to ‘Point &&’ with[
_Ty=Point
]
Reason: cannot convert from ‘Point *’ to ‘Point’
No constructor could take the source type, or constructor overload resolution was ambiguous
I understand that using new gives a pointer back and that .push_back can’t accept that, however, I have no idea on how to go about fixing that.
How are you defining your vector?
If its
vector<Point>, try changing it tovector<Point*>. This tells the vector to store pointers to the objects instead.