C++ Field holding objects with different template arguments -


i have following setup:

// n number of rooms template <size_t n> class house {     void printnumberofrooms(); }   house<1> house1; house<2> house2; 

now want have field can hold both house1 , house2 , on can call house.printnumberofrooms().

house house; house.printnumberofrooms(); 

gave me "requires template argument" error (obviously).

what best way achieve goal?

house<1> , house<2> different , incompatible types, therefore can't store them in single field.

however can give them same parent class , store them pointer parent class , make printnumberofrooms virtual. this:

class basehouse{ virtual void printnumberofrooms(); }; template<size_t n> class house: public basehouse{ virtual void printnumberofrooms(); }; class c{ basehouse * house; }; 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -