次のコードで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);
}
}