创建树节点时vtable的未定义引用
undefined reference for vtable when creating tree nodes
我是一名学生,正在处理一个数据结构类,在上次作业中遇到了一些麻烦。目的是使用我们教授提供的一些预定义的节点类创建一个二进制表达式树。我们提供的文件如下。
表达式节点.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'
如果有人能指出我做错了什么,那将是一个很大的帮助。
看起来ConstantNode::getValue已声明但未定义。只要定义函数的主体,它就应该很好地链接。。。
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用