2014-10-17 34 views
0

在我.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)我有一個意外的限定符id之前const。

回答

2

拷貝構造函數應該寫成的定義如下:

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

BST::BinaryNode在左邊是類名;右邊的BinaryNode是函數名稱。