Boost logo

Boost :

From: Artyom Borodkin (art_at_[hidden])
Date: 2005-12-09 00:37:39


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)
{ ... }


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk