【问题标题】:Unexpected qualifier Id before constconst 之前的意外限定符 Id
【发布时间】:2014-10-17 01:40:08
【问题描述】:

在我的.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。

【问题讨论】:

    标签: c++ class constructor constants copy-constructor


    【解决方案1】:

    复制构造函数定义如下:

    BST::BinaryNode::BinaryNode(const BST::BinaryNode &otherNode)
                 //^^^^^^^^^^^^^
    {
        //...
    }
    

    左边的BST::BinaryNode是类名;右边的BinaryNode 是函数名。

    【讨论】:

      猜你喜欢
      • 2016-04-20
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-11
      相关资源
      最近更新 更多