VS2013 - 类方法的decltype不起作用,因为默认模板参数不起作用

时间:2013-12-10 16:40:03

标签: c++ visual-c++ c++11 visual-studio-2013 decltype

我有以下代码:

template<typename T1,
         typename T2 = decltype(&T1::method)>
struct Foo {};

struct Bar
{
  void method() { }
};

template<class T> Foo<T> foo(T&)
{
  return Foo<T>();
}

int main()
{           
  Bar t;
  foo(t);
}

简而言之,我想使用方法的decltype作为默认模板参数,而VS对此并不满意:

source.cpp(18): error C2893: Failed to specialize function template 'Foo<T,T::method> foo(T &)'
      With the following template arguments:
      'T=Bar'

另一方面,gcc和clang对此很好(http://ideone.com/VuMZaO)。此外,将decltype移动到foo定义可以解决此错误。

那么 - 这是MSVC中的一个错误吗?

0 个答案:

没有答案