Interview Question
Developer AdvocatesCountry: United States
class Point{
private:
int x, y;
public:
Point(int xval, int yval):x(xval),y(yval){}
Point operator+(const Point& other)
{
this->x += other.x;
this->y += other.y;
return *this;
}
void print()
{
std::cout << "x: " << x << "\n";
std::cout << "y: " << y << "\n";
}
};
int main()
{
Point p1(1,2);
Point p2(3,4);
Point p4(4,5);
Point p3 = p1+p2+p4;
p3.print();
}
- NoOne April 03, 2017