.


:




:

































 

 

 

 





( ) :

_ <> _ [(_)];

. .

: List ( 24 2).

List <int> List_int;

List <double> List_doub1e;

List <monstr> List_monstr;

Block <char, 128> buf;

Block <monstr, 100> stado;

, :

template<class = char> class String:

String <>* p;

, , .

, :

for (int i = 1; i<10; i++) List_double, add(i * 0.08);

List_double.print();

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

for (int i = 1; i<10; i++) List monstr.add(i);

List_monstr.print();

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

strcpy(buf, " ");

cout << buf << endl;

typedef:

typedef List <double> Ldbl;

Ldbl List_double;

, , , , . .

- , , () .

, . , print List :

template <class Data> void List <Data>::print();

:

void List <char>::print(){

... // print

}

List char, .

. .

: Block 100 .

class Block<int, 100>{

public:

lock (){ = new int [100];}

~Block (){delete [ ] p;}

operator int * ();

protected:

int * p;

};

Block<int, 100>::operator int *(){return ;}

Block int 100 .

, , :

template<class > class { //

int ;

};

template<class > class <*> { //

long ;

};

template<template<class U> class V> class C{

V<int> y;

V<int*> z;

};

...

C<A> c;

V<int> C<A> , .. int, V<int*> - , c.z.x long.

. .

, , . , , . .

 

2.12

, , .. .

( ) , , .

.

.

, . private, protected public:

class : [private | protected | public] _

{ };

private, - public.

, . :

class {... };

class {... };

class {... };

class D: , protected , public {... };

2.1. protected . , , private. .

2.1

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

 

 

private . .

protected private private, . public .

private, , public :

class Base{

public: void f();

};

class Derived: private Base{

public: Base::void f();

};

, .

: monstr daemon, .

enum color {red, green, blue};

// monstr

class monstr{

// :

int health, ammo;

color skin;

char *name;

public:

// :

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

monstr (color sk);

monstr (char * nam);

monstr(monstr &M);

// :

~monstr() {delete [ ] name;}

// :

monstr& operator ++(){++health; return *this;}

monstr operator ++(int){ monstr M(*this); health++: return M;}

operator int(){ return health;}

bool operator >(monstr &M){

if(health > M.health) return true;

return false;

}

const monstr& operator = (monstr &M){

if (&M == this) return *this;

if (name) delete [] name;

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;

return *this;

}

// :

int get_health() const {return health;}

int get_ammo() const {return ammo;}

// , :

void change_health(int he){ health = he;}

// :

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

};

// monstr

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

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

monstr::monstr(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::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];

strcpy(name, nam);

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

}

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

{ /* monstr */ }

 

// daemon

class daemon: public monstr{

int brain;

public:

// :

daemon(int br = 10){brain = br;};

daemon(color sk): monstr (sk) {brain = 10;}

daemon(char * nam): monstr (nam) {brain = 10;}

daemon(daemon &M): monstr (M) {brain = M.brain;}

// :

const daemon& operator = (daemon &M){

if (&M == this) return *this;

brain = M.brain;

monstr::operator = (M);

return *this;

}

// , :

void think();

// :

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

};

// daemon

void daemon::think(){ /*... */ }

void daemon::draw(int x, int y, int scale, int position)

{ /*... daemon */ }

daemon brain think, , draw.

monstr, ( ) get_health, get_ammo change_health daemon, .

daemon , monstr, .. private.

, , , :

protected,

,

( ).

daemon draw, monstr. , , . , (::).





:


: 2016-11-12; !; : 583 |


:

:

, - , ; , - .
==> ...

1271 - | 1304 -


© 2015-2024 lektsii.org - -

: 0.031 .