Хочу зробити масив об'єктів, але чомусь виникає посилка при їх виведені
▼класи
class book
{
private:
char *_name;
int _length;
protected:
char *getNameBook() { return _name; }
int getLengthBook() { return _length; }
virtual char *getNameClass() = 0;
public:
book() = delete;
book(char *name, int length) : _name(name), _length(length) {}
};
class educational : public book
{
protected:
char *getNameClass()
{
return "educational";
}
public:
educational(char *name, int length) : book(name, length) {}
friend ostream &operator<<(ostream &os, educational &obj)
{
return os
<< obj.getNameClass()
<< ": "
<< obj.getNameBook()
<< "; book: "
<< obj.getLengthBook()
<< ";\n";
}
};
class scientific : public book
{
protected:
char *getNameClass()
{
return "educational";
}
public:
scientific(char *name, int length) : book(name, length) {}
friend ostream &operator<<(ostream &os, scientific &obj)
{
return os
<< obj.getNameClass()
<< ": "
<< obj.getNameBook()
<< "; book: "
<< obj.getLengthBook()
<< ";\n";
}
};
class legislative : public book
{
protected:
char *getNameClass()
{
return "educational";
}
public:
legislative(char *name, int length) : book(name, length) {}
friend ostream &operator<<(ostream &os, legislative &obj)
{
return os
<< obj.getNameClass()
<< ": "
<< obj.getNameBook()
<< "; book: "
<< obj.getLengthBook()
<< ";\n";
}
};
Виникає така помилка:
"Error (active) no operator "<<" matches these operands"
{
educational *a = new educational("!educational!", 255);
scientific *b = new scientific("!scientific!", 255);
legislative *c = new legislative("!legislative!", 255);
//array
book *arr[] = { a, b, c };
//Робить
cout << *a;
cout << *b;
cout << *c;
for (book *ele : arr)
{
cout << *ele;//ТУТ ПОМИЛКА!!!!!!!!!!!!!!!!!!
}
delete c;
delete b;
delete a;
}
Чому ? Як виправити помилку ?