我有一个动态模板数组作为我班级的成员。但是,我无法在构造函数或任何其他函数中调整数组的大小。我对语法感到困惑。这是代码:
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<Type>
HeapNode 类中包含的对象数组。这是 HeapNode 类的构造函数:
template <class Type> class HeapNode {
private:
int key;
Type value;
public:
HeapNode(int key, Type const &value) {
this->key = key;
this->value = value;
}