我有一个动态模板数组作为我的课程的一员。但是,我无法在构造函数或任何其他函数中调整数组的大小。我对语法感到困惑。下面的代码:如何调整动态模板数组的大小?
template <class Type> class MaxHeapTree {
private:
HeapNode<Type> *array[];
HeapNode<Type> *root;
int elementSize;
int height;
int leafCounter;
public:
// Constructor
MaxHeapTree(int n = 10) : elementSize(0), height(0), leafCounter(0) {
HeapNode<Type> *array = new HeapNode<Type>[n];
}
该数组是从HeapNode类包括HeapNode<Type>
对象的阵列。以下是HeapNode类的构造函数:
template <class Type> class HeapNode {
private:
int key;
Type value;
public:
HeapNode(int key, Type const &value) {
this->key = key;
this->value = value;
}
使用'的std :: VECTOR'代替。 –
与调整“动态非模板数组”的方式相同。 – juanchopanza