2015-06-28 62 views
-2

我的代码;错误:太多模板参数列表

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){ 

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

+0

这是什么附加'typename '在'template typename '...? – vsoftco

+0

它自动化类型转换 – user4578093

+0

我的意思是语法。它看起来像一个错字,你在模板decl之外有一个'typename ',并且没有依赖类型,所以不需要'typename'。 – vsoftco

回答

1

使用

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

,而不是

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

编译器首先把事实的运营商是在公共领域的说明,并有两个模板列表而不是一个,而不是提的是,操作员无效。然后输出错误的模糊错误,而不是检测到函数没有被列为成员函数。

+0

我希望这可以帮助一些人。我总是复制我的类定义,然后在做大量样板代码时替换相关的字段,所以这种事情会随着我的意愿而下滑。 – user4578093