Justin
Justin

Reputation: 111

Why is this section of code being ignored?

In the following code, set_black_hole() is never called. Why?

I added small print statements to both set_black_hole() and set_data(). Set_data() gets called repeatedly as expected, but set_black_hole() is never called. When I run a debugger and set a breakpoint just before the call for set_black_hole(), it just skips to the if() statement right after it.

Thoughts?

Is this a template specific issue by chance?

/******************************************************************
*   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);
   }

}

Upvotes: 0

Views: 245

Answers (1)

Joel Daignault
Joel Daignault

Reputation: 111

Have you tried recompiling/rebuilding the project? I encountered this issue before in Visual Studio, when the project was referencing an old build while I was debugging, because the 'build before running' option was accidentally toggled off in Visual Studio. A good indication of this is if you set a breakpoint on the line where you call set_black_hole(), and the breakpoint becomes transparent when you try to debug.

Upvotes: 1

Related Questions