c++ - How to use an STL container to hold template based shared_ptr? -


i want construct container hold shared_ptrs template based. example, have:

template <class t> class data {     .... };  template <class t> struct dataptr {     typedef boost::shared_ptr<data<t> > type; };  template <class t> struct mapdata {     typedef typename std::map<std::string, dataptr<t>::type > type; };  mapdata<int>::type data; void func(const std::string& str, dataptr<int>::type& sth) {     if (sth)     {         data[str] = sth;     } } 

now have few issues. compiler not allow me use dataptr::type when define mapdata, error message "expected type, got ‘dataptr::type". if drop type , use

template <class t> struct mapdata {     typedef typename std::map<std::string, dataptr<t> > type; }; 

then "data[str] = sth" not pass ("no match ‘operator=’").

what should correct way?

many thanks.

you've misplaced positioning of typename keyword:

typedef std::map<std::string, typename dataptr<t>::type > type; //                            ^^^^^^^^ 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -