2013-07-19 47 views
0

我是一名学生,他正在为数据结构类添加内容,并在我的上次作业中遇到一些麻烦。其目的是使用教授提供的一些预定义的节点类创建二进制表达式树。我们提供的文件如下。创建树节点时对于vtable的未定义引用

表达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();   

}; 

然后说我有是从我自己的功能版本()有问题的代码

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'

如果有人能指出我做错了什么,这将是一个很大的帮助。

回答

1

它看起来像是声明了ConstantNode :: getValue,但未定义。只需定义功能的主体,它应该很好地链接...

相关问题