我的代码,目前来了与它在StackOfBoxes.cpp的40行发现编译错误。该错误是一个未定义的引用错误:为什么我会得到一个未定义的引用错误
StackOfBoxes.cpp:40: undefined reference to
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;
}
哪一行是40行?为什么你的代码从一个大括号开始?请修改您的标题,它在一个词的中间被切断。 – Barmar
欢迎来到SO!我认为你需要提供完整的代码,最好是一个暴露错误的最小例子。 –
我打算出去走一走,猜测你在一个单独的文件中声明了Box类,并且没有在StackofBoxes.cpp中包含“#include”Box.h“'。如果是这种情况:将Box类的声明放在.h文件中,并将其包含在你的cpp文件中。 –