CCCPaste

2d8a28a83b08c

#include <iostream>
using namespace std;

class A {
int a, b;
public:
A() {
a = 0; b = 0;
}

A(int a, int b) {
this->a = a;
this->b = b;
}

//setA, setB, GetA, GetB;
void setA(int a) {
this->a = a;
}
int getA() {
return this->a;
}
void setB(int b) {
this->b = b;
}
int getB() {
return this->b;
}

bool operator > (A& obj) {
if (this->a > obj.getA()) {
return true;
}
return false;
}

bool operator == (A& obj) {
if (this->a == obj.getA()) {
return true;
}
return false;
}

bool operator < (A& obj) {
if (this->a < obj.getA()) {
return true;
}
return false;

}

A operator + (A& obj) {
A res(0, 0);
res.setA(this->a + obj.getA());
return res;
}

A operator - (A& obj) {
A res(0, 0);
res.setA(this->a - obj.getA());
return res;
}

A operator * (A& obj) {
A res(0, 0);
res.setA(this->a * obj.getA());
return res;
}

A operator / (A& obj) {
A res(0, 0);
res.setA(this->a / obj.getA());
return res;
}

void operator++() {
this->a++;
}

void operator--() {
this->a--;
}

void operator << (int n) {
this->a << n;
}
void operator >> (int n) {
this->a >> n;
}

int operator [] (unsigned int i){
if (i == 0) {
return this->a;
}
else {
return this->b;
}
}

double operator() (double p){
return this->a * p;
}
};

int main() {
A obj1(50, 100);
A obj2(100, 20);
if (obj1 > obj2)
cout << "obj1 > obj2" << endl;
else
cout << "obj1 <= obj2" << endl;

A res = obj1 + obj2;
++obj1;
double result = obj1(3.14);
cout << "result: " << result << endl;
obj1 << 3;
cout << obj1.getA();
cout << obj1[0] << ' ' << obj1[1] << endl;

}