【发布时间】:2023-03-09 21:23:01
【问题描述】:
举个例子:
template < class T > struct Dummy
{
typedef const T & type;
};
struct Type
{
int i = 0;
bool operator == (const Type & o) { return i == o.i; }
};
template < class T > struct Test
{
template < class U >
bool F(typename Dummy< T >::type a, typename Dummy< U >::type b) const
{
return a == b; // dummy operation
}
};
int main()
{
Type a, b;
// error: no matching function for call to 'Test<Type>::F(Type&, Type&)'
// note: template argument deduction/substitution failed:
// note: couldn't deduce template parameter 'U'
bool x = Test<Type>{}.F(a, b);
}
我从编译器得到一个错误,无法推断出方法的第二个参数。我在这里做错了什么?
【问题讨论】:
标签: c++11 templates type-deduction