gpt4 book ai didi

c++ - 错误 : too many template-parameter-lists

转载 作者:行者123 更新时间:2023-12-02 11:12:43 26 4
gpt4 key购买 nike

我的代码;

template<typename T, int N>
class ngon{
point<T> vertices[N];
...
template<typename O> ngon<T,N>& operator=(const ngon<O,N> otyp);
// O stands for other, as in other type
...
};

...
template<typename T, int N> typename<typename O>
ngon<T,N>& operator=(const ngon<O,N> otyp){
for (int i = 0; i < N; i++)
vertices[i] = point<T>(otyp.vertices[i]);
return this;
}

给出错误;
.\Libraries/.\Geometry\Polygon_D2.hpp:103:11: error: too many template-parameter-lists
ngon<T,N>& operator=(const ngon<O,N> otyp){

我做错什么了?模板都是正确的。

最佳答案

采用

ngon<T,N> ngon<T,N>::operator=(const ngon<O,N> otyp){

代替
ngon<T,N> operator=(const ngon<O,N> otyp){

编译器首先注意到该运算符在公共(public)域中并且有两个模板列表而不是一个这一事实,而不是注意到该运算符无效。然后它会输出一些误导性的错误,即您的模板有问题,而不是检测到该函数没有像应有的那样被列为成员函数。

关于c++ - 错误 : too many template-parameter-lists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31094812/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com