Boost logo

Boost Users :

From: David A. Greene (greened_at_[hidden])
Date: 2006-01-25 10:54:41


Well, if nothing else, I'm learning lots about the corners of the
language!

I've got the following testcase:

#include <boost/shared_ptr.hpp>

#include <iostream>

template<typename Base>
class Handle {
public:
   typedef boost::shared_ptr<Base> type;
};

template<typename Type>
void print_shared_ptr(boost::shared_ptr<Type> ptr)
{
   std::cout << "Value is " << *ptr << std::endl;
}

template<typename Type>
void print_handle(typename Handle<Type>::type ptr)
{
   std::cout << "Value is " << *ptr << std::endl;
}

int main(void)
{
   Handle<int>::type iptr(new int(10));

   print_shared_ptr(iptr);
   print_handle<int>(iptr);
   print_handle(iptr);

   return(0);
}

The calls to print_shared_ptr and the first print_handle resolve just
fine but the compiler (g++ 4.0.2) can't seem to resolve the final call
to print_handle:

shared_ptr.cc: In function 'int main()':
shared_ptr.cc:29: error: no matching function for call to
'print_handle(boost::shared_ptr<int>&)'

The point of class Handle is to hide the implementation detail
that boost::shared_ptr is being used to manage resources. I
would like the ability to easily change the type of smart
pointer used throughout the application.

What's going on here? Is there a way to make this work without
having to explicitly specify the type to print_handle?

Thanks.

                                -Dave


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net