Пардон за кривую тему форума.
В общем проблема в следующем:
У меня есть базовый класс room, от него наследуются классы game_room, bad_room и dinning_room.
Мне необходимо внести данные о размерах каждой комнаты и вывести их при условии, что имеется еще один класс Building,
который включает в себя массив указателей родительского типа на наследуемые классы.
В классе Building имеется метод вывода всех данный на экран, вот как раз с ним проблема. Результатом являются данные неинициализированные.
Подскажите как решить такую проблему?
class room
{
public:
char name;
int square;
int amount_people;
room()
{
name = '-';
square = 1000;
amount_people = 1111;
}
virtual void set_data(char n, int s)=0;
void View()
{
cout<<"Name: "<<this->name<<"."<<endl;
cout<<"Square: "<<this->square<<"."<<endl;
cout<<"People: "<<this->amount_people<<"."<<endl;
}
virtual~room(){}
};
class dinning_room:public room
{
public:
dinning_room():room()
{}
void set_data(char n, int s)
{
name = n;
square = s;
amount_people = square;
}
};
class Building
{
public:
int amount_of_structure;
int amount_of_rooms;
int amount_of_floors;
room* a[100];
Building(int s, int r, int f)
{
amount_of_structure = s;
amount_of_rooms = r;
amount_of_floors = f;
}
void set(char ch, int square, int i)
{
switch(ch)
{
case 'd':
{
dinning_room obj;
this->a[i] = &obj;
break;
}
//И далее все виды комнат
}
}
void View()
{
for(int i =0; i < amount_of_rooms; i++)
a[i]->View();
}
Извините за миллион кода.