0

I am getting ALLOT of syntax errors and token errors for this header.

#pragma once
#include "Book.h"
#include <string>
using namespace std;
/**
* This is a node class, they will hold object
* data and nodes will be utilized in List class
*/
class Node
{
public:
    /**
    * Purpose: Default constructor
    * Parameters: none
    * Returns: none
    * Pre-conditions: none
    * Post-conditions: NULL node is added to Linked List
    */
    Node();

    /**
    * Purpose: De-constructor
    * Parameters: none
    * Returns: none
    * Pre-conditions: none
    * Post-conditions: Node is deleted
    */
    ~Node();

    /**
    * Purpose: Parameterized constructor
    * Parameters: Book
    * Returns: none
    * Pre-conditions: none
    * Post-conditions: node is added to Linked List
    *                  with data
    */
    Node(Book* B);

    /**
    * Purpose: Name getter
    * Parameters: none
    * Returns: Book
    * Pre-conditions: Item name is not NULL
    * Post-conditions: none
    */
    Book* getBook();

    /**
    * Purpose: Next node getter
    * Parameters: none
    * Returns: Pointer for next node in list
    * Pre-conditions: Must have another node in list ahead of this
    * Post-conditions: none
    */
    Node* getNextNode();

    /**
    * Purpose: Next node setter
    * Parameters: pointer for next node in list
    * Returns: none
    * Pre-conditions: none
    * Post-conditions: List has new node ahead of this
    */
    void setNextNode(Node* a);

private:
    Book* thisBook;
    string itemName;
    string itemType;
    int itemNum;
    Node* nextNode;
};

Everything seems to be in order, but I am getting these errors

Error   C2061   syntax error: identifier 'Book'     38  

Error   C2535   'Node::Node(void)': member function already defined or declared     38  

Error   C2143   syntax error: missing ';' before '*'    47  

Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    47  

Error   C2238   unexpected token(s) preceding ';'   47  

Error   C2143   syntax error: missing ';' before '*'    68  

Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    68  

Error   C2238   unexpected token(s) preceding ';'   68  

I am creating a linked list and these types of errors are also appearing on my List.h file. Is there some sort of deceleration that I am missing? As for the second error, it's pointing to the parameterized constructor.

EDIT: Book definition code

#pragma once
#include "Node.h"
#include "List.h"
#include <string>
using namespace std;

/**
* Class designed to store information
* of a book. This class is the BASE.
*/
class Book
{
private:
    string author;
    string title;
    double price;

public:

    /**
    * Purpose: Default constructor
    * Parameters: none
    * Returns: none
    * Pre-conditions: none
    * Post-conditions: none
    */
    Book();

    /**
    * Purpose: Constructor
    * Parameters: author, address, price
    * Returns: none
    * Pre-conditions: none
    * Post-conditions: variables saved
    */
    Book(string, string, double);

    /**
    * Purpose: Getter for Author class
    * Parameters: none
    * Returns: Author class
    * Pre-conditions: none
    * Post-conditions: none
    */
    string getAuthor();

    /**
    * Purpose: Getter for title
    * Parameters: none
    * Returns: title
    * Pre-conditions: title must have been saved
    * Post-conditions: none
    */
    string getTitle();

    /**
    * Purpose: Getter for price
    * Parameters: none
    * Returns: price
    * Pre-conditions: price must have been saved
    * Post-conditions: none
    */
    double getPrice();
};

1 Answers1

1

If both of these headers are included in the same file, depending on the order it will try to define Node before Book

In order to account for this dependency, either make sure they are included in the right order, or declare Book without defining it before class Node

class Book;

class Node
{
    ...
};
rtpax
  • 1,687
  • 1
  • 18
  • 32