Cannot print the contents of a Linked List

Hello everybody! I'm having a difficulty printing the contents of a list.
The following for loop will not run at all.I mean even if the list was empty the for loop should run and print. Weird thing is that the program compiles.

header file:

struct LsaStorage{
int originNodeId
int neighborID
int seqNumber
};

typedef LsList<LsaStorage> DtnLsaStorageList;

cc file:
LsaStorage tempstorage;
DtnLsaStorageList templist;


tempstorage.originatorID = originNodeId;
tempstorage.neighborID = neighborId_;
tempstorage.seqNumber = sequenceNumber_;
templist.push_back(tempstorage);

for(DtnLsaStorageList::iterator itr = templist.begin(); itr != templist.end(); itr++)
{
printf("\n( Seqnum: %u, Ornode: %d, Neighbornode: %d )\n",itr->seqNumber,itr->originatorID,itr->neighborID);
}


Thank you in advance for your time!
This definitely won't compile. LsList, originatorID, and the three initializer variables are all undefined. Overall there doesn't seem to be a problem in the logic. If you change the above to include the right headers, fix the invalid names, and so tempstorage is given legitimate values, there won't be an issue.

If the list is empty, it won't print anything. templist.begin() will equal templist.end() and the body of the for loop won't run.

In the future, please use code tags to format the code in your post (look for the box with <> on the right or bottom of the page) .
Looks fine, it should print.
It will be interesting to see the implementation of "LsList". seeing the use of templates, looks you are an experienced programmer, why dont you debug inside and see whats going on.
Last edited on
Topic archived. No new replies allowed.