Question

I am a student tacking a data structures class and running into some trouble for my last assignment. The purpose is to create a binary expression tree using some predefined classes of nodes that our professor has supplied. The file we are provided is below.

Expression 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();        

}; 

Then the code that I am having a problem with is from my own function 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...
     }

  }
}

when i attempt to compile i get undefined reference to 'vtable for ConstantNode'

if anybody could point me to what i am doing wrong that would be a great help.

Was it helpful?

Solution

It looks like ConstantNode::getValue is declared but undefined. Just define the body of the function and it should link fine...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top