在下面的代码中,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()
的行上设置了一个断点,那么当您尝试调试时该断点将变得透明。
关于c++ - 为什么这部分代码被忽略了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15181644/