如何破坏数组

bob*_*bob 2 c++ arrays

#include <cstdlib>
#include <iostream>

using namespace std;

const unsigned long MAX_SIZE = 20;
typedef int ItemType;

class Heap {
private:
        ItemType array[MAX_SIZE];
        int elements; //how many elements are in the heap
public:
      Heap( )
       ~Heap( )
       bool IsEmpty( ) const
      bool IsFull( ) const
      Itemtype Retrieve( ) 
      void Insert( const Itemtype& )
};
Run Code Online (Sandbox Code Playgroud)

假设我将此作为我的头文件.在我的实现中,做Heap()构造函数和~Heap()析构函数的最佳方法是什么.

我有

Heap::Heap()
{
   elements = 0;
}

Heap::~Heap()
{
   array = NULL;
}
Run Code Online (Sandbox Code Playgroud)

我想知道这是否是在这种情况下破坏和构造数组的正确方法.

Alo*_*hal 8

array不是动态分配的,因此当范围中不再存在该对象时,它的存储会消失.事实上,你无法重新分配array; 这样做是错误的.