C++ Using pointers to template objects -
i have class named abc has class template:
template <class t> class abc{}
in class trying store of objects abc in list:
class cde{ private: list<abc *> some_list; }
i intend store objects of abc might have different class template parameters. necessary specify template pointer @ compile time? if container supposed store objects of different type? not possible?
is necessary specify template pointer @ compile time ?
yes.
what if container supposed store objects of different type ? not possible ?
it not (directly) possible.
there no such thing class abc. there instantiations of abc, such abc<foo>
, abc<bar>
. these different classes.
you can like:
template<typename t> class abc : public abc_base { ... } list<abc_base*> some_list;
by doing this, of abc instantiations have common base type, , can use base pointer arbitrarily.
Comments
Post a Comment