Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Example {
- int x;
- int y;
- public:
- Example(int x, int y): x(x), y(y) {
- }
- int getX() {
- return x;
- }
- int getY() {
- return y;
- }
- Example operator+(const Example &a) const{
- return Example(this->x + a.x, this->y + a.y);
- }
- Example operator+(int i) {
- return Example(this->x + i, this->y + i);
- }
- Example operator*(const Example& a) const {
- return Example(this->x * a.x, this->y * a.y);
- }
- Example operator*(int i) {
- return Example(this->x * i, this->y * i);
- }
- Example& operator=(const Example &a) {
- if (this == &a) {
- return *this;
- }
- this->x = a.x;
- this->y = a.y;
- std::cout << this << "\n";
- return *this;
- }
- Example& operator++() {
- this->x++;
- this->y++;
- return *this;
- }
- Example operator++(int) {
- Example temp(this->x, this->y);
- this->x++;
- this->y++;
- return temp;
- }
- bool operator==(Example &p) {
- return (x == p.x && y == p.y);
- }
- bool operator==(int i) {
- return (x == i || y == i);
- }
- friend Example operator+(int i, Example& a);
- };
- Example operator+(int i, Example& a) {
- return Example(a.x + i, a.y + i);
- }
- void findThese(Example objects[], int elements, int goal) {
- for (int i = 0; i < elements; i++) {
- if (objects[i] == goal) {
- std::cout << "Object[" << i << "] = Correct!\n";
- }
- else {
- std::cout << "Object[" << i << "] = Wrong!\n";
- }
- }
- }
- int main()
- {
- Example a(10, 40);
- Example b(20, 10);
- Example sum(0, 0);
- sum = (a + b);
- std::cout << sum.getX() << " " << sum.getY() << "\n";
- Example objects[5] = { {1,2},{3,4},{4,3},{2,1},{5,2} };
- findThese(objects, 5, 2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement