在我的.h
中,我有一个带有结构的类:
class BST
{
public:
struct BinaryNode
{
//variables
BinaryNode& operator=(const BinaryNode node) ;
BinaryNode(SequenceMap i);
~BinaryNode();
BinaryNode(const BinaryNode &otherNode);
};
};
在我的.cpp
中,我实现了我的复制构造函数:
BST::BinaryNode(const BST::BinaryNode &otherNode)
{
item = otherNode.item;
if(otherNode.left != nullptr)
left = otherNode.left;
else
left = nullptr;
if(otherNode.right != nullptr)
right = otherNode.right;
else
right = nullptr;
}
当它编译时,在BST::BinaryNode(const BST::BinaryNode &otherNode)
上,const之前有一个意外的限定符id。
复制构造函数的定义应如下所示:
BST::BinaryNode::BinaryNode(const BST::BinaryNode &otherNode)
//^^^^^^^^^^^^^
{
//...
}
左边的BST::BinaryNode
是类名;右边的CCD_ 5是函数名。