2016-12-08 43 views
0

我正在爲此標題獲取ALLOT的語法錯誤和令牌錯誤。(C++)節點標題的語法錯誤

#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; 
}; 

一切似乎是爲了,但我得到這些錯誤

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 

我創建一個鏈表,這些類型的錯誤也出現在我的List.h文件。我缺少某種減速嗎?至於第二個錯誤,它指向參數化的構造函數。

編輯:書定義代碼

#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(); 
}; 
+0

編譯器日誌已經是你的好朋友 - 仔細閱讀並理解每個錯誤是什麼。像'丟失;'應該是顯而易見的 – artm

+2

我不假設Book.h包含Node.h? – aschepler

+0

@aschepler我相信你是對的:) –

回答

1

如果這兩個頭都包含在同一個文件,根據訂單,它會嘗試之前Book

定義Node爲了考慮到這一點依賴關係,要麼確保它們包含在正確的順序中,要麼聲明Book而沒有定義它之前class Node

class Book; 

class Node 
{ 
    ... 
}; 
+0

這些是獨立的頭文件。謝謝你的信息。 –

+0

嘗試了此操作並將列表和節點組合在一起。有效!謝謝! –