c++ - 为什么这部分代码被忽略了?

标签 c++ templates

在下面的代码中,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/

相关文章:

c++ - 每当我更改 QTableWidget.item(row, col) 时发生访问冲突

c++ - 为具有未知返回类型的可调用启用部分模板特化?

c++ - 我如何为多种键类型专门化标准映射?

c++ - 错误 : class is not a template

c++ - 基于条件的编译时类型选择的可变参数模板

c++ - 如何使用 LuaBridge 注册模板函数?

c++ - OpenCV SURF 类错误

c++ - 从模板参数继承是不好的做法吗?

c++ - 无法将 char[33] 转换为 LPCTSTR,或者如果我将类型转换为 LPCTSTR,则无法获得所需的结果

c++ - 尝试处理类的 vector 成员时程序崩溃