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

我的代码;

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)域中并且有两个模板列表而不是一个这一事实,而不是注意到该运算符无效。然后它会输出一些误导性的错误,即您的模板有问题,而不是检测到该函数没有像应有的那样被列为成员函数。

https://stackoverflow.com/questions/31094812/

相关文章:

c# - 并非所有代码路径都返回值: Unity

java - Unresolved 编译问题: The method parseInt(String

java - 错误 : variable data might not have been init

c# - 错误 'Cannot Convert double to int'

java - 为什么我无法定义数组?

c++ - 奇怪的错误: undefined reference to `class::class(

sql-server - 从以下脚本获取错误

c++ - ISO C++禁止声明多集

c++ - 尝试编译我的wxWidgets程序时出现 “is_enum not declared i

c++ - 代码块错误