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

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

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -