Thread: Doubly linked list compile error

  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    U.K.
    Posts
    148

    *SOLVED* Doubly linked list compile error

    *SOLVED*

    Hi there,

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

    This is my program:

    main.cpp :
    Code:
    #include <iostream>
    #include "node.h"
    #include "doublylinkedlist.h"
    using namespace std;
    
    int main()
    {
    	system ("PAUSE");
    	return 0;
    }

    node.h :
    Code:
    class Node
    {
    public:
    	Node *pointertonextnode;//pointer to the next node of type node
    	Node *pointertopreviousnode;//pointer to the previous node of type node
    
    	int nodedatamember;//a node's data memeber
    };

    doublylinkedlist.h :
    Code:
    class doublylinkedlist
    {
    public:
    
    	Node *pointertofrontoflist;//pointer to front of list   
    	Node *pointertobackoflist;//pointer to back of list  
    
    	//constructor to contruct a blank doubly linked list:
    	doublylinkedlist()
    	{
    		pointertofrontoflist = NULL;
    		pointertobackoflist = NULL;
    	}
    
    	void insertBeginningWhenListIsEmpty(doublylinkedlist List, Node newNode);
    };

    doublylinkedlist.cpp :
    Code:
    #include "doublylinkedlist.h"
    
    void doublylinkedlist::insertBeginningWhenListIsEmpty(doublylinkedlist List, Node newNode)
    {
    	if(List.pointertofrontoflist == NULL)
    	{
    		List.pointertofrontoflist = newNode;
    		List.pointertobackoflist = newNode;
    		newNode.pointertonextnode = NULL;
    		newNode.pointertopreviousnode = NULL;
    	}
    	else
    	{
    		cout << "Create a Insert before function";
    		//insert before function
    	}
    }
    In Visual Studio, the first compile error reports:

    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):

    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 Swerve; 12-03-2009 at 02:03 PM.

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    doublylinkedlist can't see the definition of Node because it isn't including Node.h
    Where are your include guards? (#pragma once of #ifndef xxx #define xx)
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User
    Join Date
    Aug 2007
    Location
    U.K.
    Posts
    148
    Thanks for helping iMalc, but I'm still having problems.

    Did I make a mistake with what you suggested?

    main.cpp:
    Code:
    #include <iostream>
    #include "node.h"
    #include "doublylinkedlist.h"
    using namespace std;
    
    int main()
    {
    	system ("PAUSE");
    	return 0;
    }

    node.h:
    Code:
    #ifndef NODE.H
    #define NODE.H
    
    class Node
    {
    public:
    	Node *pointertonextnode;//pointer to the next node of type node
    	Node *pointertopreviousnode;//pointer to the previous node of type node
    
    	int nodedatamember;//a node's data memeber
    };
    
    #endif

    doublylinkedlist.h:
    Code:
    #ifndef DOUBLYLINKEDLIST.H
    #define DOUBLYLINKEDLIST
    
    #include "node.h"
    class doublylinkedlist
    {
    public:
    
    	Node *pointertofrontoflist;//pointer to front of list   
    	Node *pointertobackoflist;//pointer to back of list  
    
    	//constructor to contruct a blank doubly linked list:
    	doublylinkedlist()
    	{
    		pointertofrontoflist = null;
    		pointertobackoflist = null;
    	}
    
    	void insertBeginningWhenListIsEmpty(doublylinkedlist List, Node newNode);
    };
    
    #endif

    doublylinkedlist.cpp:
    Code:
    #include "doublylinkedlist.h"
    #include "node.h"
    void doublylinkedlist::insertBeginningWhenListIsEmpty(doublylinkedlist List, Node newNode)
    {
    	if(List.pointertofrontoflist == NULL)
    	{
    		List.pointertofrontoflist = &newNode;
    		List.pointertobackoflist = &newNode;
    		newNode.pointertonextnode = NULL;
    		newNode.pointertopreviousnode = NULL;
    	}
    	else
    	{
    		cout << "Create a Insert before function";
    		//insert before fucntion
    	}
    }
    Also made newNode a reference.

    Visual Studio says:

    ------ Build started: Project: List, Configuration: Debug Win32 ------
    Compiling...
    main.cpp
    list\node.h(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    list\node.h(2) : error C2008: '.' : unexpected in macro definition
    list\doublylinkedlist.h(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    list\node.h(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    list\doublylinkedlist.h(15) : error C2065: 'null' : undeclared identifier doublylinkedlist.cpp
    list\doublylinkedlist.h(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    list\node.h(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    list\my doubly linked list\node.h(2) : error C2008: '.' : unexpected in macro definition
    list\doublylinkedlist.h(15) : error C2065: 'null' : undeclared identifier
    list\node.h(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    list\doublylinkedlist.cpp(5) : error C2065: 'NULL' : undeclared identifier
    list\doublylinkedlist.cpp(14) : error C2065: 'cout' : undeclared identifier
    Really appreciate any help with this

    Thanks!


    EDIT - I got it to compile now.

    Thanks again iMalc
    Last edited by Swerve; 12-03-2009 at 02:01 PM.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    People most often use underscores in the define e.g.
    Code:
    #ifndef DOUBLYLINKEDLIST_H
    but I guess you figured out that the dot was the problem and got something suitable.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem defining structure
    By MTK in forum C Programming
    Replies: 12
    Last Post: 09-08-2009, 03:26 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM