S
Søren Johansen
Hi,
I am writing a small framework for doc/view applications. For this I have a
document base class, CBaseDocument, that implements a number of load/save
functionalities and some other stuff.
As it is now, the constructor makes a semi-zombie object that has to be
either Load'ed or New'ed (New being a method of this class) before it can be
relied upon.
class CBaseDocument
{
public:
CBaseDocument();
virtual void Load(std::string const &filename);
virtual void New(std::string const &name);
...
};
I would like "raii-enable" the class instead so this zombie state could be
avoided. This would require a Load-constructor and a New-constructor, but
there are two problems with this. One, as you can see, Load and New are
virtual (well actually, this is simplified. Load is not virtual as the
example states but it calls virtual methods), and two, Load and New take
identical sets of parameters so I would have to use named constructors or
some other trick but this makes it difficult to inherit from the class.
Any suggestions to an approach would be greatly appreciated.
Søren
I am writing a small framework for doc/view applications. For this I have a
document base class, CBaseDocument, that implements a number of load/save
functionalities and some other stuff.
As it is now, the constructor makes a semi-zombie object that has to be
either Load'ed or New'ed (New being a method of this class) before it can be
relied upon.
class CBaseDocument
{
public:
CBaseDocument();
virtual void Load(std::string const &filename);
virtual void New(std::string const &name);
...
};
I would like "raii-enable" the class instead so this zombie state could be
avoided. This would require a Load-constructor and a New-constructor, but
there are two problems with this. One, as you can see, Load and New are
virtual (well actually, this is simplified. Load is not virtual as the
example states but it calls virtual methods), and two, Load and New take
identical sets of parameters so I would have to use named constructors or
some other trick but this makes it difficult to inherit from the class.
Any suggestions to an approach would be greatly appreciated.
Søren