#include <iostream>
using namespace std;
class B
{
protected:
string* tekst;
public:
B() : tekst(new string [2] {" "," "}) {}
B(const string& a) : tekst(new string [2] {a,a}) {}
B(const string& a1, const string& a2) : tekst(new string [2] {a1,a2}) {}
virtual void txt1() const = 0;
virtual void txt2() const = 0;
friend ostream& operator << (ostream&, const B&);
virtual void wypisz(ostream&) const = 0;
};
ostream& operator << (ostream& out, const B& a)
{
return a.wypisz(out);
}
class P1 : public B
{
protected:
B be;
public:
P1(const string& a1, const string& a2) : be(a1,a2) {}
void wypisz(ostream& out) const
{
return out << tekst[0] << ' ' << tekst[1];
}
void txt1() const
{
cout << be.tekst[0];
}
void txt2() const
{
cout << be.tekst[1];
}
};
class P2 : public P1
{
double liczba;
public:
P2(const string& a1, const string& a2, int a3) : P1(a1,a2), liczba(a3) {}
void wypisz(ostream& out) const
{
return out << tekst[0] << ' ' << tekst[1] << ' ' << liczba;
}
void txt1() const
{
cout << 's';
}
void txt2() const
{
cout << 'a';
}
};
int main()
{
const P1* wsk1 = new P1("coffee","bar");
// const P2* wsk2 = new P2("white","coffe",1.50);
// const P1* wsk3 = new P1("thank","you");
// B ob1("-------------");
cout << *wsk1;
// cout << wsk1->txt1(); << " " << wsk1->txt2() <<endl;
// cout << wsk2->txt1() << " " << wsk2->txt2() <<" "
// << wsk2->w1() << endl;
// cout << *wsk3 << endl;
// P1 x = *wsk1; delete wsk1; wsk1=0;
// P2 y = *wsk2; delete wsk2; wsk2=0;
// P1 z = *wsk3; delete wsk3; wsk3=0;
// tab1[0] = new B(ob1);
// tab1[1] = new P2(y);
// tab1[2] = new B(ob1);
// tab1[3] = new B(ob1);
// for(int i=0; i<4; ++i){
// cout << *tab1[i];
// delete tab1[i];
}
błąd: cannot declare field 'p1::be' to be of abstract type 'B'
Siedzę nad tym ze znajomymi już dłuższy czas i nie mamy pojęcia o co chodzi z tym błędem.