error in c++

+2 ahmedtarek mahmoud · January 11, 2015
/images/forum/upload/2015-01-11/200986ada0ba5770c0d3c32409dabb2c.png

Post a Reply

Replies

Oldest  Newest  Rating
+1 ahmedtarek mahmoud · January 12, 2015
the area has the red line beneath
+1 ahmedtarek mahmoud · January 12, 2015
thanks all 
0 c student · January 12, 2015
what's your error?
0 c student · January 12, 2015
mine compiled fine with warning and error flags.  you should also probably have a look at the prioritization of your code.  you are declaring members of "nodes" and traversing to other "nodes" which are non-existent.
0 Laura Lee · January 12, 2015
There's redundancy in your code.
node* head = 0;
head = new node;

As much as I love to initialise to zero, in this situation it is not needed.
node* head = new node;

Similarly, this is redundant.
node* tmp = head;
tmp = new node;

Instead, we can just do.
node* tmp = new node;

I can understand in C89 that variables have to be declared at the top of the block statement. That is where it would be useful to initialise to zero. In C++, if we know what we are initialising it to then it's useless to do anything else.
  • 1

C++

107,044 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator