[英]Passing object of a Templated struct to a member function of another templated class
I have a template class alpha_x give as,我有一个模板类 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_) {};
};
I have another class with an overload for operator =我有另一个类的运算符 = 重载
template <typename T>
class Scalar{
...
template <typename U,typename V>
const Scalar<T> & operator = (alpha_x<U,V> c);
...
}
When we try to define this function,当我们尝试定义这个函数时,
template <typename T,typename U,typename V>
const Scalar<T> & Scalar<T>::operator = (alpha_x<U,V> c){
//do something...
}
Now this gives an error "Too many template parameters in template redeclaration".现在这给出了一个错误“模板重新声明中的模板参数太多”。 How do I sort this out?我该如何解决这个问题?
T
template parameter is a class Scalar
's template parameter. T
模板参数是一个Scalar
类的模板参数。 Thus it needs to be specified in a separate template parameter list.因此它需要在单独的模板参数列表中指定。
Following would work:以下将起作用:
template <typename T>
template <typename U, typename V>
const Scalar<T> & Scalar<T>::operator = (alpha_x<U,V> c){
// do something...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.