template<typename T>
void f(const T &v = T());
template<>
void f<std::string>(const std::string &v)
{
std::cout << v;
}
int main(int argc, char* argv[])
{
f<std::string>();
f<std::string>("Test");
f<std::string>(std::string());
return 0;
}
The latest Visual Studio 2013 compiler gives the following compiler error for the case where the default argument should be used:
error C2440: 'default argument' : cannot convert from 'const std::string *' to 'const std::string &'
Reason: cannot convert from 'const std::string *' to 'const std::string'
No constructor could take the source type, or constructor overload resolution was ambiguous
Visual Studio 2012 and gcc-4.7 compile in order.
Update. It seems to be a VS2013 error, are there temporary workarounds that do not require significant code changes until this is fixed by MS? An error report has been sent to MS connect.
Frank source
share