2015-11-13 80 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

回答