Boost logo

Boost Users :

From: Jens Theisen (jth01_at_[hidden])
Date: 2006-01-25 12:57:00


David wrote:

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

For such a function "Type" can't be deduced. There is a certain set of
rules which specify when types can be deduced, specified in the standard,
but I can recommend the book "C++ Templates" by Vandervoorde and Josuttis
for a nicer reading on this. It also has some nice examples about really
dark corners of the language.

It's quite obvious, if you think of it: The compiler would have to insert
all possibilities for "Type" and include all those in the overload
resolution if you would want to make the language work this way.

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

Why is there a need? Presumably you're potential surrogate for shared_ptr
will also support operator *, and that's all you use in your function.

Jens


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