C++ 使用模板专门化、默认参数和VS2013编译错误

C++ 使用模板专门化、默认参数和VS2013编译错误,c++,templates,visual-c++,visual-studio-2013,C++,Templates,Visual C++,Visual Studio 2013,Visual Studio 2012和gcc-4.7编译良好 更新:由于这似乎是一个VS2013错误,是否有任何临时解决方案,在MS修复之前不需要对代码进行重大更改?错误报告是在MS connect上提交的。每当我看到模板函数出现此类问题时,我都会尝试切换到模板结构(如果您需要临时解决方法) 模板 结构foo { 静态空隙f(常数T&v=T()); }; 模板 结构foo { 静态void f(const std::string&v=std::string()) { std::cout VS20

Visual Studio 2012和gcc-4.7编译良好


更新:由于这似乎是一个VS2013错误,是否有任何临时解决方案,在MS修复之前不需要对代码进行重大更改?错误报告是在MS connect上提交的。

每当我看到模板函数出现此类问题时,我都会尝试切换到模板结构(如果您需要临时解决方法)

模板
结构foo
{
静态空隙f(常数T&v=T());
};
模板
结构foo
{
静态void f(const std::string&v=std::string())
{

std::cout VS2013拒绝此内容是错误的。但您的问题是什么?或者这只是一个咆哮?注意:
std::cout感谢您的检查!
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>(); // Error in VS2013,  OK in VS2012, gcc-4.7
    f<std::string>("Test");   // OK
    f<std::string>(std::string());  //OK
    return 0;
}
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
template<typename T>
struct foo
{
  static void f(const T &v = T());
};

template<>
struct foo<std::string>
{
  static void f(const std::string &v = std::string())
  {
    std::cout << v;
  }
};
foo<std::string>::f()
foo<std::string>::f("Text")
template<typename T>
void f_wrapper(const T &v = T())
{
  foo<T>::f(v);
}