.


:




:

































 

 

 

 


.




. () . , - .

-, , .

-:

_ _::operator*( )

{

-;

}

 

- , . operator* -, -.

, :

- , , this;

, , (), .

, , , friend .

class A{ int x; //

...

friend class B; // B A

friend void C::fun(A&);// fun C A

friend void xxx(A&,int);// xxx A

friend void C::operator+(&);// < C>+< A>

...}

 

:

., ::, .*, ?:, sizeof, ;

;

(, + , ).

, . , int C++ +, -, *, / .. () . , , . , . , , , , C++. C++ , . , , , , . :

class complex {

double re, im;

public:

complex(double r, double i) { re=r; im=i; }

friend complex operator+(complex, complex);

friend complex operator*(complex, complex);

};


, , + * ( ). + * operator+ operator*. , , b c complex, b+c ( ) operator+(b,c). . :

void f()

{

complex a = complex(1, 3.1);

complex b = complex(1.2, 2);

complex c = b;

 

a = b+c;

b = b+c*a;

c = a*b+complex(1,2);

}

 

, b=b+(c*a), b=(b+c)*a.

, :

+ - * / % ^ & | ~!

= < > += -= *= /= %= ^= &=

|= << >> >>= <<= ==!= <= >= &&

|| ++ -- [] () new delete

- , , . , . , , % !. , , , . , ** , step().

operator ( , ), , , operator<<. , . - . :

void f(complex a, complex b)

{

complex c = a + b; //

complex d = operator+(a,b); //

}


complex .





:


: 2016-11-02; !; : 435 |


:

:

.
==> ...

1320 - | 1262 -


© 2015-2024 lektsii.org - -

: 0.012 .