Iterating the task list

The next step is to iterate the list from the first link following each pNext pointer until we get to the end of the list. For each link accessed, the task should be executed. Start by writing a function that performs the execution by printing out the description of the task and then returning a pointer to the next task. Just above the main function, add the following code:

    task *execute_task(const task* pTask)     {         if (nullptr == pTask) return nullptr;         cout << "executing " << pTask->description << endl;         return pTask->pNext;     }

The parameter here is marked as const because we will not change the task object pointed to by the pointer. This indicates to the compiler that if the code does try to change the object there ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.