c++ - How to share code between two classes having same parent? -


although using mfc, believe c++ question.

i have cresizingdialog derived cdialog base class dialogs in application. gives them ability automatically (you guessed it) resize according target screen size. cresizingdialog achieves overrides cdialog's several virtual functions including onsize(), oninitdialog(), onpaint(). far , good.

now adding property sheet/page needs same resizing functionality can't use cresizingdialog base class property page. means need new base class cresizingpage derived cpropertypage contain same functionality cresizingdialog.

however code resizes dialogs , controls same. there way can reuse cresizingdialog somehow? have never used multiple inheritance, here?

i have 2 suggestions how solve this, you'll have decide easier/nicer situation.

if possible can move resizing code standalone function appropriate parameters can call 2 virtual functions.

the other way make base class template. this:

template< typename base > cresizingbase     : public base {     // override appropriate functions here };  class cresizingdialog     : public cresizingbase< cdialog > { };  class cresizingpage     : public cresizingbase< cpropertypage > { }; 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -