.


:




:

































 

 

 

 


()




++ , . , (comp) s+g. , "-" (operator function). -:

_ operator # ( ) {__-}

- :

_ operator #( );

# - (, =, +, -, ..); operator# - . - , - , -. -

comp operator+(comp s, comp g){

comp d;

d.Re = s.Re+g.Re;

d.Im= s.Im+g.Im;

return d;

}

:

comp k(7,2), e(2,5);

operator+(k, e); //

k+e; //

 

comp comp::operator+(comp g){

comp d;

d.Re = Re+g.Re;

d.Im= Im+g.Im;

return d;

}

 

_( ), , , , .. , ++ .

- , - . - , , - . , , , ( ). .

- operator *(T , T ) , , * operator * (,B).

. @ -, . :

operator @ ( )

( - , .. ). A@B c , T .operator@(), - - , . - this.

, , . ++ . . , ++? ++ ? ( ), ++ . - , . :

;

.* ;

?: ;

:: ;

sizeof() ;

# ;

## .

( ) ++.

( ) .

, .. = ++.

, . , ** ++.

@ : , ( ) . @ .operator@(), @ operator@(x,y).

' = ', ' [ ] ', ' ->' - operator=, operator[], operator-> , . " , lvalue".

'$' : , ( ) .

' $' $z z..operator $ () operator $(z).

z$ z.operator$(), operator$(z).

++ . , long m = 0; ++m m += 1, m = m + 1. . , operator *=() operator * () operator = ().

, , . , -, . m int 2 + m ..

"-, () , ". , - ' + '.

+ 2 - . operator + (2) operator +(aa,2).

2 + operator + (2,), 2.operator + (). , + _ + _ -.

. , ' + ' , , .. , - (float, double, long double) (int, long, unsigned, char), -. , - , . :

_,

, _

, .

, comp -:

comp operator+(comp x, comp )

{return(comp(x.real + y.real, x.imag + y.imag)); }

comp operator + (double x, comp y)

{return(comp(x + y.real, y.imag)); }

comp operator + (comp x, double y)

{ return(comp(x.real + y, x.imag));}

:

comp (1.0,2.0);

comp ;

= 4.0 + ;

= CC + 2.0;

= + ;

= + 20; // int double

= + ''; // char double

( ) - . - , . , comp

comp (double x)

{ real = x; imag =0.0; }

-, :

friend comp operator +(comp, comp);

6+ double, . -

operator +(comp(double(6),double(0)), )

:

compl(double r, double i = 0.0) { Re=r; Im = i; }

' + ', , comp, , . .

++ --, . . ++ ++ -- .

++ , ++ -- , .. , , operator ++() operator - -() ++ --. - . ++ -- - int. -, int. - ( ), , - int.

, - .

7.8 , - operator=()

, 99% , - operator=().

,

struct comp{

int Re, Im;

comp(){Re= 0; Im = 0;} //

comp(int r, int i){Re = r; Im = i;} //

};

 

, , .. , .

comp (comp& T) { Re = T.Re; Im=T.Im;}//

const comp& operator=(const comp& T){ //

Re = T.Re; Im = T.Im; return *this;}

~comp(){} //

, Re Im , , . , comp :

struct comp{

int* Re, *Im;

comp() { Re = new int; Im = new int; *Re = 0; *Im = 0; }

comp(int r, int i) { Re = new int; Im = new int;*Re = r; *Im = i; }

};

.

comp (comp& T) { Re = T.Re; Im=T.Im;}//

const comp& operator=(const comp& T){ //

Re = T.Re; Im = T.Im; return *this;}

~comp(){} //

, . , , , .

-, , , ..

~comp(){delete Re; delete Im;}

-, : comp A(1,1), B(2,2); A=B;, - operator=() A B , . ,

 

A.Re à 0x00000001 A.Im à 0x00000001   B.Re à 0x00000002 B.Im à 0x00000002 0x00000001 // 0x00000001 //   // B.Re à 0x00000002 ßA.Re B.Im à 0x00000002 ß A.Im

A=B;

const comp& operator=(const comp& T){ //

Re = T.Re; Im = T.Im; return *this;}

 

 

Re Im A , 1 2. , , , , , delete, .. . , 2 A, , , .

operator=() :

const comp& operator=(const comp& T) { //

*Re = *T.Re; *Im = *T.Im; return *this;

}

.. , , , . operator=() A B , ,

A.Re à 0x00000001 A.Im à 0x00000001   B.Re à 0x00000002 B.Im à 0x00000002 A.Re à 0x00000002 A.Im à 0x00000002   B.Re à 0x00000002 B.Im à 0x00000002

 

. comp , , . , . , , . , .

void fun(comp B){ }

comp A(1,1); //

fun(A); //

A.*Re = 3; //

 

fun fun fun
A.Re à 0x00000001 A.Im à 0x00000001 B.Reà 0x00000001 ßA.Re B.Imà 0x00000001 ß A.Im A.Reà. A.Imà.

 

fun() A, . fun() B A. fun() , B, delete , Re Im , A. A . , - .

. :

comp(comp& T) {

Re = new int; Im = new int; *Re = *T.Re; *Im = *T.Im;

}

, .

fun fun fun
A.Re à 0x00000001 A.Im à 0x00000001 B.Re à 0x00000001 B.Im à 0x00000001 A.Re à 0x00000001 A.Im à 0x00000001 A.Re à 0x00000001 A.Im à 0x00000001

 

, A.

 





:


: 2018-10-15; !; : 237 |


:

:

, .
==> ...

1709 - | 1578 -


© 2015-2024 lektsii.org - -

: 0.053 .