.


:




:

































 

 

 

 


.




. : ; ; ; ; ; ; . .

, . , , , .

C++. , , , .

, .


1
. .
.

, , .

, , . ( ), . . :

class <>

{

[ private: ]

< >

public:

< >

};

.

private public . , private, . . public. protected , - - - , . . , .

:

- , ( );

- const, ( ) ;

- static, auto, extern register.

.

, . (, , ) . , , .

lass monstr

{ int health, ammo;

public:

monstr(int he = 100, int am = 10){ health = he: ammo = am;}

void draw(int x, int y, int scale, int position);

int get_health(){return health;}

int get_ammo(){return ammo;}

};

health ammo, get_health() get_ammo(). , , , . , , .

, , private .

( draw). , (inline). , . () , (::):

void monstr :: draw(int x, int , int scale, int position){ /* */ }

, . . . , .

, . C++:

monstr Vasia; // monstr

monstr Super(200, 300); //

monstr stado[100]; //

monstr *beavis = new monstr (10); //

// ( )

monstr &butthead = Vasia; //

, , , . . , .

. . () −> , :

int n = Vasia.get_ammo();

stado[5].draw(2,3,4,5);

cout << beavis −> get_health();

public. private .

. .

- , void. .

- ( ).

- , , .

- , . . .

- , . . , , , , .

- .

- const, virtual static.

- main. , . (, ).

- , - :

_ _ [( )];

//

_ ( );

// ( )

_ _ = ;

//

:

monstr Super(200, 300), Vasia(50), Z;

monstr X = monstr(1000);

monstr Y = 500;

. . health = 1000 ( ). X, . health = 500 ( ). Y, . , .

monstr, , (skin) (name):

enum color {red, green, blue}; //

class monstr

{

int health, ammo;

color skin;

char *name;

public:

monstr(int he = 100, int am =10);

monstr(color sk);

monstr(char * nam);

int get_health(){return health;}

int get_ammo(){return ammo;}

};

//---------------------------

monstr::monstr(int he, int am)

{ health = he; ammo = am; skin = red; name = 0;

}

//---------------------------

monstr::monstr(color sk)

{

switch (sk)

{ case red: health = 100; ammo =10; skin = red; name = 0; break:

case green: health = 100; ammo = 20; skin = green; name = 0; break;

case blue: health = 100; ammo = 40; skin = blue; name = 0; break;

}

}

//---------------------------

monstr::monstr(char * nam)

{ name = new char [strlen(nam) + 1];

// 1 -

strcpy(name, nam);

health = 100; ammo = 10; skin = red;

}

//---------------------------

monstr * m = new monstr (Ork);

monstr Green (green);

, . monstr , . , .

:

monstr::monstr(int he, int am):

health (he), ammo (am), skin (red), name (0){}

. , . -, - -. , .

, , , .

. , .

. , . :

(const CAT & theCat);

CAT CAT, theCat.

( ) . (shallow copy). , , .

. , .

, . , , . , , , .

, , , . , , .

, , . , :

- , ;

- main;

- , , delete.

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

:

- ;

- const static;

- ;

- .

:

monstr::~monstr() {delete [] name;}





:


: 2017-02-25; !; : 470 |


:

:

- , .
==> ...

1949 - | 1744 -


© 2015-2024 lektsii.org - -

: 0.031 .