Hopefully I don't dumb down my code too much...
Index::Index() : m_first(""), m_count(0)
{
m_ll = new LinkedList;
}
void TestClass::testMethod()
{
if (getIndex(i).getCount() != 0)
{
//do stuff
}
}
Index TestClass::getIndex(int num) const
{
return m_index[num];
}
Index::~Index()
{
delete m_ll;
}
This is the code that's really involved in the crash. When I enter testMethod, I have m_index[num], which contains a pointer to m_ll. They're completely valid. After it returns m_index[num], it goes into the destructor even though m_index[num] is still in use and because of this, my program crashes. I don't understand why the destructor would be called so early.