C++ template class design with varying method return types -
c++ design question
simplified example
template <typename t> class thing { t value; public: t get() { return value; } }; template <typename t> class box { thing<t> thing; public: t get() { return thing.get(); } };
now need store different types of box,
box<string>, box<matrix>, etc
(where none of t classes related) in container. isn't possible, since t isn't same each type of box. can't create abstract superclass since return type of t varies , there nothing in get() parameters distinquish use, if somehow provide alternative implementations.
how solve reasonable way. sure add multiple get()s in abstract class doesn't seem c++ ish. @ point have check isthisastring, isthisamatrix, question what's reasonable design, assuming might need add specialized box subclasses in future still maintain set of methods similar get() based on template parameter.
Comments
Post a Comment