How can I cast a class to another type? Example:

class Point
{
    Point(int X, int Y);
};

Point A(10, 10);
POINT P = (POINT)A;
A = (Point)P;


//I've tried:

Point::Point(POINT P) : X(P.x), Y(P.y), Color(0) {} //Constructor.

Point& Point::operator ()(POINT P)
{
    if (X != P.x && Y != P.y)
    {
        X = P.x;
        Y = P.y;
        Color = 0;
    }
    return *this;
}

How do I go the other way around? I've tried doing the reverse the exact same way but it doesn't work. Did I do the above correctly?

You're looking for conversion operator. Something like

class Point{
  private:
    int x,y;
  public:
    operatir POINT()const{
       return POINT(x,y);
    }
};
commented: Perfect! I never ever saw that before. Thank you. +5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.