更新时间:2023-02-22 23:31:23
您可以使用 C ++ 11的自动返回类型语法
template<typename U>
Matrix <decltype(declval<X>()+declval<U>())> operator+(const Matrix<U> &B) const
{
Matrix< decltype( declval<X>() + declval<U>() ) > res;
// The rest...
}
这个语法,你的东西将是类型C ++通常产生的两个模板类型添加时。
With this syntax, your "something" will be the type C++ normally produces when the two template types are added.