const前面有意外的限定符Id

Unexpected qualifier Id before const

本文关键字:Id 前面 意外 const      更新时间:2023-10-16

在我的.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是函数名。