So, here's the setup:
Code: Select all
class basic_window{
public:
basic_window( point pt_, window_style style_, std::wstring title_)
{
// Does this call the derived class's override version?
_on_create( pt, style_, std::move( title_ ) );
}
protected:
virtual void _on_create( point, window_style, std::wstring ) = 0;
};
class default_window : public basic_window {
public:
private:
void _on_create( point, window_style, std::wstring) override;
};
If you don't see anything wrong with this call to _on_create() you'd be in the same boat as me. Unfortunately, this is not the case. The compiler seems to expect basic_window::_on_create to have a definition even though it's pure virtual. After looking online, it turns out this is expected behavior as default_window hasn't been fully instantiated yet, calling _on_create() in this case want to call the basic_window version.
So now I'm in a bit of a design pickle, AGAIN!!! I'm trying to keep with RAII idoms here dammit, so I don't want to two step initialization by having a separate void basic_window::create() function and it hardly makes sense to expect derived classes to call the override function upon creation does it?
The options I see before me are:
- Force derived classes to call _on_create() during their construction instead of the base class
- Move definition to basic_window::_on_create() and remove default_window::_on_create()
- Two stage initialization where basic_window::basic_window() is just a default constructor, and users must call basic_window::create() which then CAN call default_window::_on_create() because default_window will have been technically "fully initialized".