0

私はデータ構造のクラスに取り組んでいる学生で、最後の課題で問題に直面しています。目的は、教授が提供したいくつかの事前定義されたノードのクラスを使用してバイナリ表現ツリーを作成することです。私たちが提供するファイルは以下です。

式 Node.h

class ExpressionNode 
{
protected:
    string parent;
    ExpressionNode *left;   // The left operand.
  ExpressionNode *right;  // The right operand.

public: 
    // Returns the number value of this node.    
    virtual int getValue() = 0;  

    //returns parent node
    string getParent() {return parent;};

    //returns left child
    ExpressionNode* getLeft() { return left; }

    //returns right child
    ExpressionNode* getRight() { return right; }
};


//A subclass of ExpressionNode that represents a math node that holds a number value  
class ConstantNode : public ExpressionNode
{     
public:
    // Constructor.  Create a node to hold number.
    ConstantNode(string theNumber) 
    { 
        ExpressionNode::parent = theNumber;
        ExpressionNode::left = NULL;
        ExpressionNode::right = NULL;
    }


    //Returns the number value in the node
    int getValue();        

}; 

次に、私が問題を抱えているコードは、私自身の関数 build() からのものです

void myExpressionTree::build()
{
   post = this->postfixInput(); //creates the postfix input string to be read by function
   cout << post << endl; 

   for (int i =0; i < post.size(); i ++)
   {
     if (post[i] >= '0' && post[i] <='9' ) 
     {
     string num1;
     num1 += post[i]; 
     ConstantNode *num = new ConstantNode(num1); 
     theNodes.push(num); 
     }

     else if (post[i] == '*' || post[i] == '+' || post[i] == '-' || post[i] =='/')
     {
     do stuff...
     }

  }
}

コンパイルしようとすると、undefined reference to 'vtable for ConstantNode'

誰かが私が間違っていることを指摘できれば、それは大きな助けになるでしょう。

4

1 に答える 1

1

ConstantNode::getValue が宣言されているようですが、未定義です。関数の本体を定義するだけで、うまくリンクするはずです...

于 2013-07-19T20:42:32.377 に答える