, . , , , . (x + y * z) , « y, , z x». , XVI , , . . . , . .
, C++ , , . . , C++. , . , , . , sum_matrix (A, B) , A + B.
:
class complex {
double re, im;
public:
complex (double r, double i) :re(r), im(i) {}
complex operator+(complex);
complex operator*(complex);
};
void main() {
complex a{ 1, 2 }, b{ 3, 4 }, c{0, 0};
c = a + b;
c = a.operator+(b);
c = a*b + complex(1, 3);
}
, , / C++ .
,
, :
+ | - | * | / | % | ^ | & |
| | ~ | ! | = | < | > | += |
-= | *= | /= | %= | ^= | &= | |= |
<< | >> | >>= | <<= | == | != | <= |
>= | && | || | ++ | -- | ->* | , |
-> | [] | () | new | new[] | delete | delete[] |
, . . . Java, , . .
,
- – «::»;
- – «.»;
- – «.*»;
- – «?:»;
- sizeof;
- typeid.
, . . , - , Python.
:
- , .
- , . . , , .
- , . new delete. , , . , , . "=", "&" "," .
- , C++, .
- operator, .
- , . , : ++x; x + = 1; x = x + 1. . .
- . z + 5 5 +z ( z – ) -. «complex + », - « + ». .
- - , , . .
.
- . @ a@b, @ :
a.operator@(b) operator@(a, b).
.
class complex {
double re, im;
public:
complex& operator+=(complex z);
complex& operator*=(complex z);
};
complex operator+(complex z1, complex z2);
complex operator+(complex z, double a);
, , , . .
, – , -, . : (, a + = b), , ; (, a + b) – .
C++ , , :
- , , – @a, , ++i. o a.operator@() operator@(aa);
- , , – b@, , i++. o b.operator@(int) operator@(b, int)
, , , , C++.
@ x X y Y. x@y :
- X , operator@ X, X;
- , x@y;
- X N, N;
- Y M, M.
1-4 operator@, .
.
complex
, .
class complex {
double re, im;
public:
complex& operator+=(complex z) {
re += z.re;
im += z.im;
return *this;
}
complex& operator+=(double a) {
re += a;
return *this;
}
complex (): re(0), im(0) {}
complex (double r): re(r), im(0) {}
complex (double r, double i): re(r), im(i) {}
};
complex operator+(complex z1, complex z2) {
complex res = z1;
return res += z2;
}
complex operator+(complex z, double a) {
complex res = z;
return res += a;
}
complex operator+(double a, complex z) {
complex res = z;
return res += a;
}
, , . . , C++ .
. , , . 3 , 9 – 27 – . .
«[]» , . , , , .
«()» . , «( )» () «», – . operator()() .
«,» () , . .
«->» . . , , .
- .
«=», «&» «,» public.
. , – . , - .
. , . . , .
- . . , .
- .
- .
- , .
- , .
- - - , .
- .
- - .
- () .
- .