c++ - template type dependecy and inheritance -


i have template method defined as

template<class t> const std::list<t>& getlist() {   return getlist(std::shared_ptr<parent>(new t())); }  const std::list<std::shared_ptr<parent>>& getlist(const std::shared_ptr<parent>&a) {     // } 

given t type of classes take parent parent class, e.g

class child1:public parent {}; 

compilation error : can not convert const std::list<std::shared_ptr<parent>>& const std::list<t>&

is there way fix without changing type of t shared_ptr ?

the definitions have match.

typedef std::shared_ptr<parent> parentptr;  std::list<parentptr> getparentlist(const parentptr& a) {     // }  template<class child> std::list<parentptr> getparentlistt() {     parentptr parent_ptr(new child);     return getlist(parent_ptr); }  ... std::list<parentptr> my_list = getparentlistt<child1>(); 

also make sure child1 defined (and not merely declared) prior using code, otherwise compiler won't know it's subclass of parent.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -