首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

模板中的operator,该如何解决

2012-02-04 
模板中的operatortemplate typenameTclassLeftHeap{public://...constLeftHeap&operator(constLeftHeap

模板中的operator
template <typename   T>
class   LeftHeap
{
        public:
                  //...
                  const   LeftHeap   &operator=(const   LeftHeap   &rhs);

};

template <typename   T>
const   LeftHeap   &LeftHeap <T> ::operator=(const   LeftHeap <T>   &rhs)
{
if(   *this   !=   rhs   )
{
MakeEmpty();
root=Clone(rhs.root);
}
return   *this;
}

错误提示:error   C2955:   'LeftHeap '   :   use   of   class   template   requires   template   argument   list
\exercise\leftheap\leftheap\leftheap.h(45)   :   see   declaration   of   'LeftHeap '
\exercise\leftheap\leftheap\leftheap.h(178)   :   error   C2244:   'LeftHeap <T> ::operator   = '   :   unable   to   match   function   definition   to   an   existing   declaration
\exercise\leftheap\leftheap\leftheap.h(23)   :   see   declaration   of   'LeftHeap <T> ::operator   = '

要怎么解决?
谢谢

[解决办法]
C2244 can also occur when an incorrect function signature is used for a member function template.

内外定义和引用有区别。

[解决办法]
只觉得应该这样:
this != &rhs
而且, root 似乎是个指针, 好象有回收对象的问题.
其他没看出来.
[解决办法]
返回类型也要加 <T>
[解决办法]
if( *this != rhs ) //???, 这样还要定义!=, 而且比较的是内容

一般是这样的吧:
if (this != &rhs)

热点排行