templates - a C++ syntax error when passing class members in a constructor -


i need write kind of shared_ptr<> in c++. however, i'm struggling weird error.
following code:

template <typename t> class shared_ptr; typedef std::map<void*, shared_ptr<void*>> ptr_t; ptr_t ptr_set; template <typename t> class shared_ptr {     t* ptr; public:     bool in_use;     shared_ptr<t>()     {         ptr = new t;         in_use = false;         ptr_set.insert(ptr_t::value_type(ptr, *this)); // error here     }     t operator*()     {         return *ptr;     }     shared_ptr<t>(shared_ptr<t>& ref)     {         this->in_use = false;         this->ptr = ref.ptr;         t* p = this->ptr;         ptr_set.insert(ptr_t::value_type(p, *this));     } }; 

refuses compile saying 'std::pair<_ty1,_ty2>::pair: none of 2 overloads convert argument types' (c2665 in 13th line actually).
way, shared_ptr instantiated in main() shared_ptr<array_t> a, array_t struct consisting of nothing more simple array (i don't think actual source of bug). ideas?
in advance.

p.s. answer's been edited fix typo (p instead of ptr @ line 13).

of course, you'll error, because shared_ptr< t* > cannot casted shared_ptr< void* > except t void. solve can add casting operator shared_ptr class, cast type shared_ptr< void* >


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -