在下面的代码中,从未调用set_black_hole()
。为什么?
我在set_black_hole()
和set_data()
中都添加了小字体语句。Set_data()
如预期的那样被反复调用,但set_black_hole()
从未被调用。当我运行调试器并在调用set_black_hole()
之前设置断点时,它只是跳到它后面的if()语句。
想法吗?
这是模板特有的问题吗?
/******************************************************************
* build_list
* add new items to the list until input is exhausted
*/
template <typename T>
void List<T>::build_list(ifstream &fin)
{
T *pT;
bool readSuccess; // successful read of object data
bool storeSuccess; // successful node addition
pT = new T;
readSuccess = pT->set_black_hole(fin); // fill the T object
if (readSuccess) {
storeSuccess = add_node(pT);
}
while (true)
{
storeSuccess = false;
readSuccess = pT->set_data(fin); // fill the T object
if (fin.eof())
{
delete pT;
break;
}
// insert object data into the list
if (readSuccess)
storeSuccess = add_node(pT);
else // something bad happened during node setup
{
delete pT;
fatal_err(BAD_SET_DATA);
}
if (!storeSuccess) // something bad happened during store
fatal_err(BAD_ADD_NODE);
}
}
您是否尝试过重新编译/重建项目?我以前在Visual Studio中遇到过这个问题,当项目在我调试时引用旧版本时,因为在Visual Studio中不小心关闭了"运行前构建"选项。如果您在调用set_black_hole()
的行上设置了一个断点,那么当您尝试调试时,该断点将变得透明,这是一个很好的指示。