According to what I read, a virtual base class is used when you have an abstract base class that contains data, so the class will not be replicated, but what is the problem with class replication if you are not using a virtual class
And should we abstract the base class that contains the data?
follows an example:
class Storable {
public:
Storable(const string& s);
virtual void read() = 0;
virtual void write() = 0;
virtual ~Storable();
protected:
string file_name;
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 "C ++ Programming Language" 4th edition - Bjarn Stroustrup.
source
share