在下面的代码中,set_black_hole()
从不调用。为什么?
set_black_hole()
我在和中添加了小字语句set_data()
。Set_data()
按预期被重复调用,但从set_black_hole()
未被调用。当我在调用 for 之前运行调试器并设置断点时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);
}
}