I hit what appears to be the same issue in my own code. The minimal code I boiled it down to was this:
namespace N
{
template<typename T>
T defaultValue()
{
return T();
}
template<typename T>
void fun( const T& value = N::defaultValue<T>() ){}
}
int main(int argc, char* argv[])
{
N::fun<int>();
return 0;
}
This is slightly different to James McNellis example - and, I think, highlights the fact that it is the namespace qualification in the default argument initiliser where it goes wrong.
In this case defaultValue and fun are in the same namespace, so you can trivially remove N:: from N::defaultValue and it works.
If defaultValue is in a different namespace you can still workaround it by either bringing it into the local namespace with using, or writing a local forwarding template function, e.g.:
namespace N1
{
template<typename T>
T defaultValue()
{
return T();
}
}
namespace N2
{
template<typename T>
T defaultValueFwd()
{
return N1::defaultValue<T>();
}
template<typename T>
void fun( const T& value = defaultValueFwd<T>() ){}
}
int main(int argc, char* argv[])
{
N2::fun<int>();
return 0;
}
A bit of a pain, but workable. I believe you could use this technique in the make_shared case, although I haven't tried it.
shared_ptr
is instd::tr1
, andmake_shared
is not implemented (make_shared
was not part of TR1). – Schreibman::make_shared
– Cobboost::shared_ptr
and it won't compile in VS2008. It complains that it "could not deduce template argument for 'T'," which does not make any sense to me, because you explicitly specify T (int
). – Schreibman