Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 二叉树函数不适用于模板_C++_Templates_Compiler Errors_Binary Tree - Fatal编程技术网

C++ 二叉树函数不适用于模板

C++ 二叉树函数不适用于模板,c++,templates,compiler-errors,binary-tree,C++,Templates,Compiler Errors,Binary Tree,您好,如果您能帮助我理解为什么会发生以下错误,以及如何修复它,我将非常高兴。错误是二叉树的一部分 谢谢 错误- 错误C2955“BSNode”:使用类模板需要模板参数列表 代码的一部分- template <class T> BSNode& BSNode::operator=(const BSNode& other) { _data = other._data; _left = 0; _right = 0; //deep recursive copy if (oth

您好,如果您能帮助我理解为什么会发生以下错误,以及如何修复它,我将非常高兴。错误是二叉树的一部分

谢谢

错误-

错误C2955“BSNode”:使用类模板需要模板参数列表

代码的一部分-

template <class T>
BSNode& BSNode::operator=(const BSNode& other)
{
_data = other._data;
_left = 0;
_right = 0;

//deep recursive copy
if (other._left)
{
    _left = new BSNode(*other._left);
}

if (other._right)
{
    _right = new BSNode(*other._right);
}

return *this;
} 
模板
BSNode&BSNode::operator=(常量BSNode&other)
{
_数据=其他数据;
_左=0;
_右=0;
//深层递归复制
如果(其他,左)
{
_左=新BSNode(*其他。_左);
}
如果(其他._右)
{
_右=新BSNode(*其他。_右);
}
归还*这个;
} 

如消息所述,您需要提供模板参数:

BSNode<T>& ... const BSNode<T>& other ...
BSNode&。。。常量BSNode和其他。。。
编译器可能会推断两个构造函数调用的参数。如果不是这样,您也需要为它们提供参数


顺便说一句,模板通常在它们的头文件中实现,因为通常很难或不可能将它们的声明从它们的实现中分离出来。

但是在这次更正之后,我得到了以下错误“需要一个类或名称空间”怎么办?@yronmosh您能发布更多的代码吗?也许这会帮助别人理解你为什么会犯这样的错误?可能您没有使用名称空间限定模板参数?