Boost logo

Boost :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2006-06-14 11:39:58


> Have you tried
>
> #include <boost/pointer_cast.hpp>
>
> // in class
>
> {
> using boost::static_pointer_cast;
> static_pointer_cast<T>( ps );
> }
>
> under g++? Does it still fail? This is required to support the case where ps
> is a raw pointer.

This also fails. Simplified test case:

////////////////////////////////////////
//raw_ptr.hpp header:
////////////////////////////////////////

namespace raw_ptr
{

//static_pointer_cast overload for raw pointers
template<class T, class U>
inline T* static_pointer_cast(U *ptr)
{ return static_cast<T*>(ptr); }

} //namespace raw_ptr

////////////////////////////////////////
//container.hpp header:
////////////////////////////////////////

namespace dummy {

template<class Pointer>
class container
{
    public:

    void func()
    {
       using raw_ptr::static_pointer_cast;
       static_pointer_cast<int>(Pointer());
    }
};

} //namespace dummy {

////////////////////////////////////////
//smart_ptr.hpp header:
////////////////////////////////////////

namespace dummy {

template<class T>
class smart_ptr
{};

template<class T, class U>
smart_ptr<T> static_pointer_cast(const smart_ptr<U> &u)
{ return smart_ptr<T>(); }

} //namespace dummy {

////////////////////////////////////////
//main.cpp
////////////////////////////////////////

int main()
{
    using namespace dummy;
    typedef container<smart_ptr<int> > my_container;
    my_container cont;
    cont.func();

    typedef container<int *> my_container2;
    my_container2 cont2;
    cont2.func();
    return 0;
}

This compiles fine with with VC 7.1. g++ fails with:
"no matching function for call to 'static_pointer_cast(dummy::smart_
ptr<int>)'"

Regards,

Ion


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