I serialize most of my classes with two functions, read() and write(). What I would like to do is have the read/write() function of the base class called from the subclasses so that I don’t have to repeat the serialization code multiple times.
For example:
class Base
{
public:
base();
virtual read(QDataStream&);
virtual write(QDataStream&);
private:
int a, b, c, d;
}
class Sub : public Base
{
public:
Sub();
read(QDataStream&);
write(QDataStream&);
private:
int e, f, g, h;
}
So in this example, i would like the code to read/write a,b,c,d to come from Base. Sub would then call Base::read(QDataStream&) and then add whatever attributes are unique to Sub. This way I don’t have to repeat the serialization code for each subclass (and possibly forget to do so).
You can call base-class functions by prepending the function call with the base-class identifier, followed by the scope operator (::).
Like this:
EDIT: Note removed by request.