I basically have something like this:
class CGlToolBase
{
public:
CGlToolBase(void)
{
}
virtual void OnMouseDown(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam);
virtual void OnMouseMove(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam);
virtual void OnMouseUp(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam);
virtual void OnKeyDown(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam);
virtual void OnLDoubleClick(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam);
~CGlToolBase(void);
};
class CGlToolSelect : public CGlToolBase
{
bool selected;
public:
CGlToolSelect(void)
{
selected = false;
}
virtual void OnMouseDown(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam);
virtual void OnMouseMove(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam);
virtual void OnMouseUp(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam);
virtual void OnKeyDown(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam);
virtual void OnLDoubleClick(CGlEngine &glEngine, WPARAM wParam, LPARAM lParam);
~CGlToolSelect(void);
};
In my select tool I set selected to false. Is this the correct way to do it if I do something like this:
CGlToolBase *tool = new CGlToolSelect;
Thanks
That’s perfectly legal and acceptable.
However, some notes:
Your destructor should be virtual. If any class has virtual methods (abstract or not), you should have a public virtual (abstract?) destructor (so
deletecalls the children destructors) or a protected non-virtual destructor (which prevents the superclass from beingdeleted as a superclass (it must bedeleted as a subclass, thus calling the appropriate destructor)).You may want to use initializers to set
selectedin the constructor: