есть класс
class сUnit
{
int level;
public:
сUnit()
{
level=1;
}
virtual сUnit* Attack(сUnit *u)=0;
virtual void Show()=0;
};
есть классы наследники
class Spear:сUnit
{
int speed;
int attack;
int def;
public:
Spear()
{
attack=10;
def=15;
speed=2;
}
virtual сUnit* Attack(сUnit *u)
{
return (сUnit*)this;
}
virtual void Show()
{
cout<<"S";
}
};
class Swordsman:сUnit
{
int speed;
int attack;
int def;
public:
Swordsman()
{
attack=25;
def=50;
speed=1;
}
virtual сUnit* Attack(сUnit *u)
{
return (сUnit*)this;
}
virtual void Show()
{
cout<<"M";
}
};
class Axefighter:сUnit
{
int speed;
int attack;
int def;
public:
Axefighter()
{
attack=40;
def=10;
speed=3;
}
virtual сUnit* Attack(сUnit *u)
{
return (сUnit*)this;
}
virtual void Show()
{
cout<<"T";
}
};
class Archer:сUnit
{
int speed;
int attack;
int def;
public:
Archer()
{
attack=15;
def=50;
speed=5;
}
virtual сUnit* Attack(сUnit *u)
{
return (сUnit*)this;
}
virtual void Show()
{
cout<<"A";
}
};
есть ещё класс
#include <iostream>
using namespace std;
#include "Unit.h"
class cField
{
int x,y;
сUnit ***field;
public:
cField()
{
x=20;/shirina polya
y=20;/visota polya
field =new сUnit **[x];
for(int i=0; i<x; ++i)
field [ i ]=new сUnit*[y];
for(int i=0; i<x; ++i)
for(int j=0; j<y; ++j)
{
field[ i ][j]=NULL;
}
}
};
cfield поле для юнитов
x,y размеры данного поля.
Мне надо чтобы указатели моего масива указателей указывали на классы наследники - Archer, Axefighter etc.
Кто знает, помогите плиз...
Вот здесь им присваивают 0
for(int i=0; i<x; ++i)
for(int j=0; j<y; ++j)
{
field[ i ][j]=NULL;
}
}
а надо чтобы вместо NULL создавался новый обьект одного из классов-наследников. С меня
зы: сорри за нечитабельность и обёмность...
|