-, , , , :
class monstr {
monstr & operator ++() {++health; return *this;}
};
monstr Vasia;
cout << (++Vasia).get_health ();
, :
class monstr {
friend monstr & operator ++ (monstr &M);
};
monstr &operator ++(monstr &M) {++M.health; return M;}
, . health , private, . monstr change_health, health:
void change_health (in the) {health=he;}
, :
monstr &operator ++ (monstr &M) {
int h=M.get_health (); h++;
M.change_health (h);
return M;
}
int. , :
class monstr {
monstr operator ++ (int) {
monstr M(*this); health ++;
return M;
}
};
monstr Vasia;
cout <<(Vasia++).get_health ();
-, , , :
class monstr {
bool operator > (const monstr &M) {
if (health >M.get_health ()) return true;
return false;
}
};
, :
bool operator > (const monstr &M1, const monstr &M2) {
if (M1.get_health () > M2.get_health ()) return true;
return false;
}
. , . , , . , - , , .
class monstr &operator = (const monstr &M) {
//
if (&M= =this) return *this;
if (name) delete [ ] name; //
if (M.name) {
name = new char [strlen(M.name) c+1];
strcpy (name, M.name;}
else name =0;
health = M.health; ammo = M.ammo;
skin = M.skin;
return *this;
}
:
|
|
monstr A(10), B, C;
C = B = A;
. .
-, . :
perator __ ();
monstr:: operator int () {return health;}
, . private, protected public:
class : [private | protected | public]
{ };
, . , :
class A {};
class B {};
class C {};
class D: A, protected B, public C {};
private, public (. ).
private | private protected public | private private private | private |
protected | private protected public | private protected protected | protected, private |
public | private protected public | private protected public |
, private . .
, . , , .
. daemon, monstr:
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.get_heath ()) return true;
return false;
}
const monstr & operator = (monsr &M) {
if (&M = = this) return *this;
if (name) delete [ ] name;
if (M.name) {
namt = new char [strlen(M.name)+1];
strcpy (name, M.name); }
else name = 0;
health =M.health; ammj=M.ammo; skin =M.skin;
return *this;
}
//
int get_health () const {return health;}
int get_ammo () const { return ammo;}
//
void change_health (int he) {healt=he;}
//
void draw (int x, int y, int scale, int position);
//
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=1`0; 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)
{/**/}
//
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 x, int y, int scale, int position);
}
//
void daemon:: think () {/* */}
void daemon:: draw (int x, int y, int scale, int position) {/* */}
!!! daemon brain think, , draw. monstr, ( ) get_health, get_ammo change_health daemon, .