.


:




:

































 

 

 

 





- , , .. .

. , Location : Location (int _x, int _y).

, void.

- , , .

, . .

. .

, .

:

 

void main (void)

{Location NK(0,0), KK(10,10), *PL;

cout<<KK.Getx(); // : 10

PL=&NK;

cout<<PL->Gety(); // : 0

}

 

NK(0,0) KK(10,10) .

cout<<KK.Getx() .

cout<<PL->Gety() .

 

{Location A(1,1),B,D=A;

}

D A. .

.

Location::Location([const]Location &S)

{x=S.x; y=S.y}

 

. : ~ . , ~ () .

, .. .

, . . .

, . .

 

C++ , . , .

, , .

, , .

. , . , . , .

, , .

, .

 

:

class : public

, class D: public A

{ }

D , public A. , D A. public , , A , , . . , . , .

:

class D: public A [, public C]

{ D}

 

:

enum Bool

{false, true}; // int. .

class Point: public Location

{protected:

Bool vis;

public:

Point (int _x, int _y);

void Show();

void Hide();

};

Point::Point (int_x, int_y): Location(_x, _y)

{vis=false;}

Point Location.

 

, . public, . private, . .

, private, , .

, . , :

 

  public private protected public protected public  
  protected private protected public protected protected  
  private private protected public private private

 

 

this

, , , , . this () :

_ * const this= ;

 

this () . this . this , .. , , . , this () . , this , . , this, this. .

, , this.

:

comp &operator+(comp)

{real=real+x.real;

im=im+x.im;

return *this;}

comp . . this. , return this.

 

, , , .

. friend. .

 

class C

{

friend class A; }

A C.

( ): A B, B C, , A C.

 

. this. . :

_._ __->_

 

C++, , new, delete, , , , .. . , , int, double, float . C++.

, : .:: *?:

C++ , . , , .. . , . , - (operator function). -:

 

__ operator _ ( -)

{ - }

- :

 

__ operator _ ( -);

, - operator, . ,

operator _ , - C++. , * T T operator *(T x, T y).

( ) (- - overload), C++.

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

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

 

. .

class comp

{float im; float real;

public:

comp(float i, float r)

{real=r;

im=i;}

 

comp operator +(comp X)

{return comp(im+X.im, real+X.real);}

}

void main()

{

comp C1(1,1), C2(5,5),C3;

C3=C1.operator+(C2) // -. .

C3=C1+C2 // -.

}

1 2 , , +, operator +. im real , (X ).

C++ , , (->) , .. - .

, .

C++ (). , - , :

class A

{

A operator --() { }

}

- , .. , . , = static. () [].

, .

comp & operator =([const] comp & X)

{real=X.real;

im=X.im;

return *this;}

const, , , , .

.

 





:


: 2016-07-29; !; : 378 |


:

:

! . .
==> ...

1536 - | 1327 -


© 2015-2024 lektsii.org - -

: 0.025 .