boost::bind upgrading from 1.33.1 to 1.34.1 problem

Hello, I'm upgrading from boost 1.33.1 to 1.34.1 and upgrade does not let me compile the following code: // CRefCounted provides functionality to CRefPtr to have // referenced pointers struct CNode: public CRefCounted { void GetName(){} }; int main(int argc, char **argv){ typedef CRefPtr<CNode> CPNode; typedef std::multimap<std::string, CPNode> TPNodes; TPNodes Children; std::for_each( Children.begin(), Children.end(), boost::bind( &CNode::GetName, // problem in the next line boost::bind(&TPNodes::value_type::second,_1))); return 0; } I get the following messages from MSVC8.0: error C2784: 'T *boost::get_pointer(const boost::shared_ptr<T> &)' : could not deduce template argument for 'const boost::shared_ptr<T> &' from 'const CPNode' error C2784: 'T *boost::get_pointer(const std::auto_ptr<_Ty> &)' : could not deduce template argument for 'const std::auto_ptr<_Ty> &' from 'const CPNode' error C2784: 'T *boost::get_pointer(T *)' : could not deduce template argument for 'T *' from 'const CPNode' If I replace CRefPtr with boost::shared_ptr the code compiles. Hence I assume the problem is with the way I implemented CRefPtr class. Here it is: template<typename T> class CRefPtr { private: T* m_ptr; public: CRefPtr(T* ptr=NULL) :m_ptr(NULL){ *this=ptr; } CRefPtr(const CRefPtr<T>& ptr) :m_ptr(NULL){ *this=ptr; } ~CRefPtr() { if (m_ptr) { m_ptr->DecrementReference(); m_ptr=NULL; } } CRefPtr<T>& operator=(T* ptr) { if(ptr!=m_ptr) { if(m_ptr) { m_ptr->DecrementReference(); } m_ptr=ptr; if(m_ptr) { m_ptr->IncrementReference(); } } return *this; } CRefPtr<T>& operator=(const CRefPtr<T>& ptr){*this=ptr.m_ptr;return *this;} T* operator->() const{return m_ptr;} T& operator*() const{return *m_ptr;} bool operator<(const CRefPtr<T>& obj)const{if(obj.m_ptr<this->m_ptr)return true;else return false;} T* get() const{return m_ptr;} operator T*()const{return m_ptr;} }; What am I missing? Some explanation on why I went this route. I am using CRefPtr instead of shared_ptr because full CNode class has a member CNode* m_Parent. I could not figure out how to use weak pointers, but if I use CRefPtr I can assign a simple pointer returned by GetParent() to a CPNode and it would still work, while I could not achieve this result with shared_ptr. Maybe someone can direct me to a place which explains how to handle such situations properly with shared_ptr. Thanks. -- Regards, Alexander. http://sjcomp.com

boost-users-bounces@lists.boost.org, le 4 décembre 2007 22:46:
int main(int argc, char **argv){ typedef CRefPtr<CNode> CPNode; typedef std::multimap<std::string, CPNode> TPNodes; TPNodes Children; std::for_each( Children.begin(), Children.end(), boost::bind( &CNode::GetName, // problem in the next line boost::bind(&TPNodes::value_type::second,_1))); return 0; }
I get the following messages from MSVC8.0: error C2784: 'T *boost::get_pointer(const boost::shared_ptr<T> &)' : could not deduce template argument for 'const boost::shared_ptr<T> &' from 'const CPNode' error C2784: 'T *boost::get_pointer(const std::auto_ptr<_Ty> &)' : could not deduce template argument for 'const std::auto_ptr<_Ty> &' from 'const CPNode' error C2784: 'T *boost::get_pointer(T *)' : could not deduce template argument for 'T *' from 'const CPNode'
If I replace CRefPtr with boost::shared_ptr the code compiles.
Hi You probably need boost::get_pointer: http://lists.boost.org/boost-users/2007/09/30745.php HTH, Éric Malenfant --------------------------------------------- Si vous n'allez jamais à l'enterrement des gens, n'espérez pas qu'ils viennent au vôtre. - C. Lemprun

sj@sjcomp.com:
Hello,
I'm upgrading from boost 1.33.1 to 1.34.1 and upgrade does not let me compile the following code:
// CRefCounted provides functionality to CRefPtr to have // referenced pointers struct CNode: public CRefCounted { void GetName(){} };
int main(int argc, char **argv){ typedef CRefPtr<CNode> CPNode; typedef std::multimap<std::string, CPNode> TPNodes; TPNodes Children; std::for_each( Children.begin(), Children.end(), boost::bind( &CNode::GetName, // problem in the next line boost::bind(&TPNodes::value_type::second,_1))); return 0; }
I get the following messages from MSVC8.0: error C2784: 'T *boost::get_pointer(const boost::shared_ptr<T> &)' : could not deduce template argument for 'const boost::shared_ptr<T> &' from 'const CPNode' error C2784: 'T *boost::get_pointer(const std::auto_ptr<_Ty> &)' : could not deduce template argument for 'const std::auto_ptr<_Ty> &' from 'const CPNode' error C2784: 'T *boost::get_pointer(T *)' : could not deduce template argument for 'T *' from 'const CPNode'
If I replace CRefPtr with boost::shared_ptr the code compiles. Hence I assume the problem is with the way I implemented CRefPtr class. Here it is: template<typename T> class CRefPtr {
... You need to implement get_pointer for CRefPtr. Add the following after CRefPtr's definition: template<class T> T* get_pointer( CRefPtr<T> const & p ) { return p.get(); } or use boost::intrusive_ptr.
participants (3)
-
Eric MALENFANT
-
Peter Dimov
-
sj@sjcomp.com