943,106 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 815
  • C++ RSS
Dec 3rd, 2009
0

Doubly linked list compile error

Expand Post »
Hi,

I'm trying to construct my first Doubly Linked List, but am having trouble compiling.

This is my program:

main.cpp :
c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include "node.h"
  3. #include "doublylinkedlist.h"
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. system ("PAUSE");
  9. return 0;
  10. }


node.h :
c++ Syntax (Toggle Plain Text)
  1. class Node
  2. {
  3. public:
  4. Node *pointertonextnode;//pointer to the next node of type node
  5. Node *pointertopreviousnode;//pointer to the previous node of type node
  6.  
  7. int nodedatamember;//a node's data memeber
  8. };


doublylinkedlist.h :
c++ Syntax (Toggle Plain Text)
  1. class doublylinkedlist
  2. {
  3. public:
  4.  
  5. Node *pointertofrontoflist;//pointer to front of list
  6. Node *pointertobackoflist;//pointer to back of list
  7.  
  8. //constructor to contruct a blank doubly linked list:
  9. doublylinkedlist()
  10. {
  11. pointertofrontoflist = NULL;
  12. pointertobackoflist = NULL;
  13. }
  14.  
  15. void insertBeginningWhenListIsEmpty(doublylinkedlist List, Node newNode);
  16. };


doublylinkedlist.cpp :
c++ Syntax (Toggle Plain Text)
  1. #include "doublylinkedlist.h"
  2.  
  3. void doublylinkedlist::insertBeginningWhenListIsEmpty(doublylinkedlist List, Node newNode)
  4. {
  5. if(List.pointertofrontoflist == NULL)
  6. {
  7. List.pointertofrontoflist = newNode;
  8. List.pointertobackoflist = newNode;
  9. newNode.pointertonextnode = NULL;
  10. newNode.pointertopreviousnode = NULL;
  11. }
  12. else
  13. {
  14. cout << "Create a Insert before function";
  15. //insert before function
  16. }
  17. }

In Visual Studio, the first compile error reports:

Quote ...
error C2143: syntax error : missing ';' before '*'
Which is the line in bold within the doublylinkedlist.h file.

I can't see the error which would cause this, and so am stumped.

Could anyone point my error?

Many thanks for any help with this!


//-------------------------------------------------
(Full error list if that will help):

Quote ...
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2061: syntax error : identifier 'Node'
error C2065: 'pointertofrontoflist' : undeclared identifier
error C2065: 'NULL' : undeclared identifier
error C2065: 'pointertobackoflist' : undeclared identifier
error C2061: syntax error : identifier 'Node'
error C2039: 'pointertofrontoflist' : is not a member of 'doublylinkedlist'
see declaration of 'doublylinkedlist'
error C2039: 'pointertofrontoflist' : is not a member of 'doublylinkedlist'
see declaration of 'doublylinkedlist'
error C2065: 'newNode' : undeclared identifier
error C2039: 'pointertobackoflist' : is not a member of 'doublylinkedlist'
see declaration of 'doublylinkedlist'
error C2228: left of '.pointertonextnode' must have class/struct/union
Last edited by Carrots; Dec 3rd, 2009 at 1:05 pm.
Similar Threads
Reputation Points: 41
Solved Threads: 0
Junior Poster in Training
Carrots is offline Offline
62 posts
since Mar 2009
Dec 3rd, 2009
1
Re: Doubly linked list compile error
does your class doublylinkedlist know what a class Node is? if not, trying to create a pointer to one will surely result in an error.

EDIT: I tested it and that wasn't the problem.
I used the Visual Studio pre-compiled header, fixed the lines 7&8 in doublylinkedlist.cpp ( &newNode ) and it compiled fine.
Last edited by Topi Ojala; Dec 3rd, 2009 at 1:39 pm.
Reputation Points: 13
Solved Threads: 17
Junior Poster in Training
Topi Ojala is offline Offline
59 posts
since May 2009
Dec 3rd, 2009
0
Re: Doubly linked list compile error
Thanks for helping Topi, but I'm still having problems.

Did I make a mistake with what you suggested?

main.cpp:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include "node.h"
  3. #include "doublylinkedlist.h"
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. system ("PAUSE");
  9. return 0;
  10. }


node.h:
C++ Syntax (Toggle Plain Text)
  1. #ifndef NODE.H
  2. #define NODE.H
  3.  
  4. class Node
  5. {
  6. public:
  7. Node *pointertonextnode;//pointer to the next node of type node
  8. Node *pointertopreviousnode;//pointer to the previous node of type node
  9.  
  10. int nodedatamember;//a node's data memeber
  11. };
  12.  
  13. #endif


doublylinkedlist.h:
C++ Syntax (Toggle Plain Text)
  1. #ifndef DOUBLYLINKEDLIST.H
  2. #define DOUBLYLINKEDLIST
  3.  
  4. #include "node.h"
  5. class doublylinkedlist
  6. {
  7. public:
  8.  
  9. Node *pointertofrontoflist;//pointer to front of list
  10. Node *pointertobackoflist;//pointer to back of list
  11.  
  12. //constructor to contruct a blank doubly linked list:
  13. doublylinkedlist()
  14. {
  15. pointertofrontoflist = null;
  16. pointertobackoflist = null;
  17. }
  18.  
  19. void insertBeginningWhenListIsEmpty(doublylinkedlist List, Node newNode);
  20. };
  21.  
  22. #endif


doublylinkedlist.cpp:
C++ Syntax (Toggle Plain Text)
  1. #include "doublylinkedlist.h"
  2. #include "node.h"
  3. void doublylinkedlist::insertBeginningWhenListIsEmpty(doublylinkedlist List, Node newNode)
  4. {
  5. if(List.pointertofrontoflist == NULL)
  6. {
  7. List.pointertofrontoflist = &newNode;////////////////////
  8. List.pointertobackoflist = &newNode;////////////////////
  9. newNode.pointertonextnode = NULL;
  10. newNode.pointertopreviousnode = NULL;
  11. }
  12. else
  13. {
  14. cout << "Create a Insert before function";
  15. //insert before fucntion
  16. }
  17. }

Visual Studio says:

Quote ...
unexpected tokens following preprocessor directive - expected a newline
Really appreciate any help with this

Thanks!
Reputation Points: 41
Solved Threads: 0
Junior Poster in Training
Carrots is offline Offline
62 posts
since Mar 2009
Dec 26th, 2009
0
Re: Doubly linked list compile error
should the "name" given in the preprocessor command match on lines 1 and 2 in doublylinkedlist.h ?

other than that I'm not sure what the problem might be ( or you might have figured it out by now
Reputation Points: 13
Solved Threads: 17
Junior Poster in Training
Topi Ojala is offline Offline
59 posts
since May 2009
Dec 27th, 2009
0
Re: Doubly linked list compile error
Topi is on the right track I think. A portion of it has to do with your preprocessor directives. I've never seen one with a period in it and this is why I suppose. Most people use an underscore in place of the period (the convention is to name it after your header like you had done, but really it could be anything). So change those to NODE_H, DOUBLYLINKEDLIST_H etc.

NULL is something that is defined in a couple of the headers so it has to be in all caps. You need to include <iostream> for the NULL and the couts. Also you need to qualify cout one of 3 ways: either put std:: in front of it, std::cout, or put using std::cout; at the top of your file, or the last option put using namespace std; at the top of your file (which is the least favorable since you have to worry about all the names in that namespace conflicting with the code you've written.
Sponsor
Featured Poster
Reputation Points: 1165
Solved Threads: 578
Quantitative Phrenologist
jonsca is offline Offline
4,271 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: right click
Next Thread in C++ Forum Timeline: No error, still no output





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC