我有以下代码:
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中的一个错误吗?