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:
Expand|Select|Wrap|Line Numbers
- 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.