[shared_ptr] conversion problem

9 Dec
2005
9 Dec
'05
5:06 a.m.
This following code does not work, but it could. You should just add the template constructor. So, why not? #include <boost/shared_ptr.hpp> #include <iostream> class A{}; class B{}; class C : public A{}; void foo( boost::shared_ptr<A> pa ){ std::cout << "A"; } void foo( boost::shared_ptr<B> pb ){ std::cout << "B"; } int main(){ boost::shared_ptr<C> ptr(new C); foo( ptr ); return 0; } //--------------------------- If add this template constructor it will help with ambiguous problem. template< class T2 > shared_ptr( const shared_ptr<T2>& s_ptr, typename enable_if<is_convertible<T*,T2*>::result, void* >::type = 0) { ... }
7125
Age (days ago)
7125
Last active (days ago)
0 comments
1 participants
participants (1)
-
Artyom Borodkin