I have a ShapeType, Point, with some coordinates, (1,2), and I'd like to use apply_visitor in an overloaded operator () to add the coordinates (3,4) to my Point, so that Point ends up being (4,6). Where is my implementation failing? I think my ShapeVisitor class is correct, but I am getting an error, "apply_visitor" is not a member of CLARK::Point.
Code is as follows.
#include "Point_H.hpp"
#include "Shape_H.hpp"
#include "boost/variant.hpp"
typedef boost::variant<Point,Line,Circle> ShapeType;
ShapeType ShapeVariant(){...}
class ShapeVisitor : public boost::static_visitor<>
{
private:
double m_dx; // point x coord
double m_dy; // point y coord
public:
ShapeVisitor(double m_dx, double m_dy);
~ShapeVisitor();
// visit a point
void operator () (Point& p) const
{
p.X(p.X() + m_dx);
p.Y(p.Y() + m_dy);
}
};
int main()
{
using boost::variant;
ShapeType myShape = ShapeVariant(); // select a Point shape
Point myPoint(1,2);
boost::get<Point>(myShape) = myPoint; // assign the point to myShape
boost::apply_visitor(ShapeVisitor(3,4), myPoint); // trying to add (3,4) to myShape
cout << myPoint << endl;
return 0;
}
Thanks!