如何破坏数组 [英] how to destruct an array
本文介绍了如何破坏数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#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& )
};
假设我有这个头文件。在我的实现中,这是什么是做Heap()构造函数和〜Heap()析构函数的最好方法。
Let's say I have this as my header file. In my implementation for this, what is the best way to do Heap() constructor and ~Heap() destructor.
我有
Heap::Heap()
{
elements = 0;
}
Heap::~Heap()
{
array = NULL;
}
我想知道这是否是正确的方法来销毁和构造数组这种情况。
I am wondering if this is the proper way to destruct and construct an array in this case.
推荐答案
数组
不是动态分配,因为当对象不再存在于范围内时它会消失。实际上,您不能重新分配数组
;这是一个错误。
array
is not dynamically allocated, so the storage for it goes away when the object no longer exists in scope. In fact, you can't reassign to array
; it's an error to do so.
这篇关于如何破坏数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文