【发布时间】:2020-04-01 20:06:40
【问题描述】:
我有一个模板类 alpha_x 作为,
template <typename T,typename U>
struct alpha_x {
const T & alpha;
const Scalar<U> & x;
alpha_x(const T & a_, const Scalar<U> & x_) : alpha(a_), x(x_) {};
};
我有另一个类,运算符重载 =
template <typename T>
class Scalar{
...
template <typename U,typename V>
const Scalar<T> & operator = (alpha_x<U,V> c);
...
}
当我们尝试定义这个函数时,
template <typename T,typename U,typename V>
const Scalar<T> & Scalar<T>::operator = (alpha_x<U,V> c){
//do something...
}
现在这会给出错误“模板重新声明中的模板参数过多”。我该如何解决这个问题?
【问题讨论】:
-
你试过
template <typename T> template<typename U,typename V>吗? -
这解决了...谢谢