Hello,
I need help with the design of a serialization template base class.
The idea is that any class derived from this template base class would only need to implement the input and output operators and a named constructor, Create().
The code is something like this:
As I know, the input and output operators must be friend functions to the type they provide I/O for, so they cannot be member functions. But then I can't promise the compiler that the operators will be implemented for SerializableCla ss, so this doesn't compile.
Is there a way to make this design work?
Also, I think I miss some point of either the I/O operators or design with templates, so help with that is also appreciated.
I need help with the design of a serialization template base class.
The idea is that any class derived from this template base class would only need to implement the input and output operators and a named constructor, Create().
The code is something like this:
Code:
template <class SerializableClass>
class Serializable
{
public:
static SerializableClass* Unserialize(std::istream& in){
SerializableClass* instance = SerializableClass::Create();
in >> *instance;
return instance;
}
std::ostream& Serialize(std::ostream& out){
out << *this;
return out;
}
protected:
static Create();
};
Is there a way to make this design work?
Also, I think I miss some point of either the I/O operators or design with templates, so help with that is also appreciated.
Comment