.


:




:

































 

 

 

 





 

/++ , .

.

- () , .

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

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

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


 

 

, , .

, ( /++ - -, ). . :

Class {

[private:]

< >

public:

< >

};

private public . , private, . . public. . private public, .

:

- , ( );

- const, ( ) ;

 

- static, auto, extern register.

.

( ) ( ).

. , :

class 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, int get_health () get_ammo (). , ( draw). , (inline). , . () , (::):

void monstr:: draw (int x, int y, int scale, int position) {

/* */

}

inline:

inline int monstr:: get_ammo() {

return ammo;

}

, . . .

 

, .

 

.

monstr Vasia; //

monstr Super(200,300); //

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

//

monstr & butthead = Vasia; //

. . () -> :

int n = Vasia.get_ammo();

stado [5].draw;

cout << beavis ->get_ammo();

public. private .

, . :

class monstr {

int get_health () const {return health;}

};

const monstr Dead (0,0); //

cout << Dead.get_health ();

 

this

 

. , , . this, .

this . (return this;) (return *this;) .

monstr , ( health) , , ( public ):

Monstr & the_best (monstr &M) {

If (health >M.get_health ()) return *this;

Return M;

}

monstr Vasia (50), Super (200);

monstr Best = Vasia.the_best (Super); //

// Best Super

this , . (::):

void cure (int health, int ammo) {

this -> health +=health; // this

monstr:: ammo +=ammo; // ::

}

 

 

. :

- void. ;

- ( );

- , , ;

- , . . ;

- , ;

- ;

- const, virtual static;

, ;

- , - :

_ _ [( )];

//

_ ( );

//

_ _ = ;

//

 

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

monstr X = monstr (1000);

monstr Y = 500;

.

health = 1000; X, .

health= 500; Y, . , .

 

. monstr :

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 = red; name = 0;

break;

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

break;

}

}

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

monstr:: monstr (char *nam) {

name = new char [strlen(nam)+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 (sk), name (0) {};

. , . -, - -. , .

 

- , .

 

, :

T:: T(const &T) {/* */}

T .

, :

- ;

- ;

- .

, .

monstr:

Monstr:: (const monstr &M) {

if (M.name) {

name = new char [strlen (M.name) +1];

strcpy(name, M.name);}

else name = 0;

health =M.health; ammo= M.ammo; skin=M.skin;

}

monstr Vasia (blue);

monstr Super = Vasia; //

monstr *m=new monstr (Ork);

monstr Green = *m; //

 

static . , .

 

, . , .. .

.

1. , ( ):

class A {

public:

static int count; //

};

int A:: count; //

//

// int A:: count =10; 10.

2. , :

A *a, b;

cout << A::count << a->count <<b.count;

//

3. , , private, , . .

4. , , sizeof.

. , this. , :

class A {

static int count;

public:

static void inc_count () {count ++;}

};

A::int count;

void f () {

A a;

a.inc_count (); // A::inc_count ();

.

 





:


: 2016-10-06; !; : 772 |


:

:

,
==> ...

1744 - | 1508 -


© 2015-2024 lektsii.org - -

: 0.054 .