2015-11-13 37 views
-1

來自此文件的錯誤heap.h。重新定義MAX_HEAP時出錯,並且heapclass。 我一直在收到一個錯誤,它的重新定義,但我沒有看到另一個定義。任何其他原因? 錯誤在這裏找到。爲什麼我會得到重定義錯誤C++?

// ********************************************************* 
// Header file Heap.h for the ADT heap. 
// ********************************************************* 

#include "Data.h" // definition of itemClass 

const int MAX_HEAP = 20; 
typedef itemClass keyType; 

typedef itemClass heapItemType; 

class heapClass 
{ 
public: 
    heapClass(); // default constructor 
    // copy constructor and destructor are 
    // supplied by the compiler 

    // heap operations: 
    virtual bool HeapIsEmpty() const; 
    // Determines whether a heap is empty. 
    // Precondition: None. 
    // Postcondition: Returns true if the heap is empty; 
    // otherwise returns false. 

    virtual void HeapInsert(const heapItemType& NewItem, 
          bool& Success); 
    // Inserts an item into a heap. 
    // Precondition: NewItem is the item to be inserted. 
    // Postcondition: If the heap was not full, NewItem is 
    // in its proper position and Success is true; 
    // otherwise Success is false. 

    virtual void HeapDelete(heapItemType& RootItem, 
          bool& Success); 
    // Retrieves and deletes the item in the root of a heap. 
    // This item has the largest search key in the heap. 
    // Precondition: None. 
    // Postcondition: If the heap was not empty, RootItem 
    // is the retrieved item, the item is deleted from the 
    // heap, and Success is true. However, if the heap was 
    // empty, removal is impossible and Success is false. 

protected: 
    void RebuildHeap(int Root); 
    // Converts the semiheap rooted at index Root 
    // into a heap. 

private: 
    heapItemType Items[MAX_HEAP]; // array of heap items 
    int   Size;    // number of heap items 
}; // end class 
// End of header file. 


here are the other files included 
main contains main 

main

Data.cpp

Data.h

Heap.cpp

PQ.cpp

PQ.h

Thank you 
+0

我懷疑你收到此文件包含超過一次,因爲你沒有包括警衛。 –

+0

PQ.h包含「Heap.h」。 Heap.cpp包含「Heap.h」。 MAX_HEAP定義了兩次 – bassxzero

回答

相關問題