Consider this example:
#include <memory>
template<typename T>
class A {};
template<typename T1, typename T2>
class B: public A<T1> {};
template<typename T = int>
void foo(std::shared_ptr< A<T> > test)
{
}
int main()
{
auto p = std::make_shared<B<int, int>>();
foo<int>(p); // Works
foo<>(p); // Does not work
foo(p); // Does not work
}
I'm trying to get this to compile without explicitly specifying the type T for foo, but it doesn't work. I'm not sure why as if I explicitly the type T, it works just fine, but if I it, it doesn't compile, even though I've told the compiler the what the type T should be if I don't explicitly specify it.
I get why the compiler can't deduce the type T, but why can't it use my default type T when I don't specify it? How do I get around this and what is the "proper" way of doing this?