0% found this document useful (0 votes)
68 views2 pages

Supraincarcarea Operatorilor - App 2

This C++ code defines a MyOperator class that overloads operators such as ++, --, and =. It includes default and parameterized constructors, a print method, and friend functions to overload the increment, decrement, and assignment operators. The main function declares MyOperator objects, uses the overloaded operators on them, and prints output.

Uploaded by

Dragu Stelian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views2 pages

Supraincarcarea Operatorilor - App 2

This C++ code defines a MyOperator class that overloads operators such as ++, --, and =. It includes default and parameterized constructors, a print method, and friend functions to overload the increment, decrement, and assignment operators. The main function declares MyOperator objects, uses the overloaded operators on them, and prints output.

Uploaded by

Dragu Stelian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

using namespace std;

class MyOperator
{
private:
int x;
int y;
public:
MyOperator()
{
cout << "\n MyOperator() default called." << endl;
}
MyOperator(int x, int y)
{
this->x = x;
this->y = y;
cout << "\n MyOperator() parameter called." << endl;
}
void print()
{
cout << "\n X = " << x << endl;
cout << "\n Y = " << y << endl;
}
friend MyOperator operator++(MyOperator &box);
friend MyOperator operator--(MyOperator &box);
MyOperator operator=(MyOperator box)
{
x = box.x;
y = box.y;
cout << "\n Operator= overload called." << endl;
return *this;
}
};

MyOperator operator++(MyOperator &box)


{
box.x++;
box.y++;
cout << "\n Operator++ overload called." << endl;
return box;
}

MyOperator operator--(MyOperator &box)


{
box.x--;
box.y--;
cout << "\n Operator-- overload called." << endl;
return box;
}

int main()
{
MyOperator obj1(100, 200);
MyOperator obj2(400, 500);
obj1.print();
obj2.print();
++obj1;
obj1.print();
obj2 = ++obj1;
obj2.print();
--obj2;
obj2.print();
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy