{ int x,y; //
public:
dek_koord(){};
dek_koord(int X,int Y): x(X),y(Y) {}
dek_koord operator*(const dek_koord);
dek_koord operator=(const dek_koord);
dek_koord operator>(const dek_koord);
int operator ==(const dek_koord);
void see();
};
dek_koord dek_koord::operator*(dek_koord a) // *
{ dek_koord tmp; //
tmp.x=x*a.x;
tmp.y= y*a.y;
return tmp;
}
dek_koord dek_koord::operator =(const dek_koord a)
{ x=a.x; // =
y=a.y;
return *this;
}
dek_koord dek_koord::operator >(const dek_koord a)
{ if (x<a.x) x=a.x; // >
if (y<a.y) y=a.y;
return *this;
}
int dek_koord::operator ==(const dek_koord a) // ==
{ if (x==a.x && y==a.y) return 0; // 0
if (x>a.x && y>a.y) return 1; //
if (x<a.x && y<a.y) return -1; //
else return 2; //
}
void dek_koord::see() //
{ cout << " = " << x << endl;
cout << " y = " << y << endl;
}
int main()
{ dek_koord A(1,2), B(3,4), C;
int i;
A.see();
B.see();
C=A*B; // * =
C.see();
C=A>B; // max
C.see();
i=A==B; // i A==B (−1,0,1,2.)
// cout << A==B << endl; //
// error binary '<<': no operator defined which takes a right-hand operand
// of type 'class dek_koord' (or there is no acceptable conversion)
cout << (A==B) << endl; //
}
:
= 1
y = 2
= 3
y = 4
= 3
y = 8
= 3
y = 4
* , , :
dek_koord &dek_koord::operator*(const dek_koord &a)
{ x*=a.x;
y*=a.y;
return *this;
}
operator* , *, .. . () . . operator* (- ). this, .. . A*B*C.
, dek_koord *:
class dek_koord
{...
dek_koord operator*(const dek_koord);
dek_koord &operator*(const dek_koord &);
...
};
. , , − .
operator , .
, operator* .