gpt4 book ai didi

c++ - 为什么我收到重新定义错误C++?

转载 作者:行者123 更新时间:2023-12-02 11:09:12 25 4
gpt4 key购买 nike

来自此文件heap.h的错误。重新定义MAX_HEAP和heapclass时出错。
我一直在得到一个错误,它的重新定义,我没有看到另一个定义。还有其他原因吗?
在这里找到错误。

// *********************************************************
// 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

最佳答案

应该使用“#pragma once”来防止头文件内容的多次包含。
看到:
https://msdn.microsoft.com/en-us/library/4141z1cx.aspx?f=255&MSPPError=-2147217396

另请参阅:
Is #pragma once a safe include guard?

关于c++ - 为什么我收到重新定义错误C++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33702969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com