According what I read, virtual base class is used when you have a abstract base class that holds data, so the class wont be replicated, but, what is the problem with replicate the class, if you don't use virtual class?
And should abstract base class that holds data be avoided?
follows an example:
class Storable {
public:
Storable(const string& s);
virtual void read() = 0;
virtual void write() = 0;
virtual ~Storable();
protected:
string file_name; // store in file named s
Storable(const Storable&) = delete;
Storable& operator=(const Storable&) = delete;
};
class Transmitter : public virtual Storable {
public:
void write() override;
// ...
};
class Receiver : public virtual Storable {
public:
void write() override;
// ...
};
class Radio : public Transmitter, public Receiver {
public:
void write() override;
// ...
};
This example was taken from the book The C + + Programming Language 4th Edition - Bjarne Stroustrup.