gpt4 book ai didi

c++ - 创建树节点时 vtable 的 undefined reference

转载 作者:行者123 更新时间:2023-11-28 07:30:52 25 4
gpt4 key购买 nike

<分区>

我是一名正在学习数据结构类(class)的学生,在上一次作业中遇到了一些麻烦。目的是使用我们的教授提供的一些预定义节点类来创建二叉表达式树。我们提供的文件如下。

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

};

然后我遇到问题的代码来 self 自己的函数 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'

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com