为什么我会收到未定义的引用错误
Why am I getting an undefined reference error
我的代码目前正在StackOfBoxes.cpp的第40行找到编译错误。该错误是未定义的引用错误:
StackOfBoxes.cpp:40:未定义对
Box::Box();
的引用
我不确定该怎么做才能进行调试。任何帮助将不胜感激。
bool StackOfBoxes::isEmpty() const
{
if (m_size == 0)
{
return false;
}
else
{
return true;
}
}
int StackOfBoxes::size() const
{
return m_size;
}
void StackOfBoxes::push(int value)
{
Box* box = m_top;
m_top = new Box();
m_top->m_value = value;
m_top->m_previous = box;
// increase m_size by 1;
m_size += 1;
}
int StackOfBoxes::pop()
{
// Create a Box pointer (Box* temp) and store the value of m_previous using m_top
Box* temp = m_top->m_previous;
// Similarly store the m_value using m_top into the Integer variable
int x = m_top->m_value;
// Delete top of the stack
delete m_top;
// make the current Box pointer your new m_top
m_top = temp;
return x;
}
我的猜测是你已经用一个构造函数声明了盒子,如下所示:
class box {
public:
box(void);
};
但后来没有继续定义构造函数,例如:
box::box(void)
{
....
}
要么是那个,要么是那个文件没有被链接。
我猜这是第 40 行m_top = new Box();
此错误的可能原因是您尚未定义默认构造函数。
相关文章:
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++引用错误
- 已定义函数时出现 G++ "未定义的引用"错误
- 链接 cmake 时出现未定义的引用错误
- 只有级联分类器会发出未定义的引用错误
- 2个模板化类的非模板友元函数未定义引用错误
- C/C++ 取消引用错误:在空检查之前取消引用
- 为什么我的C++代码无法编译,出现未定义的引用错误
- 我的代码中C++未定义的引用错误?
- 模板专用化会导致未定义的引用错误
- .cpp文件中未定义的引用错误
- c++ 中目录中文件的未定义引用错误
- Opencv4 使用 pkg-config 给出未定义的引用错误
- 使用Cygwin C++时出现未定义的引用错误,为什么我的文件没有链接?
- 共享指针取消引用错误
- 编译简单的多文件类程序时出现未定义的引用错误
- 模板函数产生未定义的引用错误
- 调用提取重加载器会产生对"运算符"的未定义引用错误>>
- 如何修复"未定义的引用"错误 opencv 和 g++
- 未定义的引用错误,我该怎么办?