Итак, я пытаюсь создать массив указателей на объект для шаблонного списка. Я посмотрел на кучу других подобных вопросов, но все еще не могу заставить мой работать, я предполагаю, что что-то не так с синтаксисом.
Вот определение класса для моего GLRow:
//************************************************************************************
// GLROW CLASS
//************************************************************************************
template <class DT>
class GLRow; //class prototype
template <class DT>
ostream& operator <<(ostream& s, GLRow<DT>& oneGLRow);
template <class DT>
class GLRow {
friend ostream& operator<< <DT>(ostream& s, GLRow<DT>& oneGLRow);
protected:
DT* _Info;
int _Next;
int _Down;
public:
GLRow ();
GLRow (const DT& newInfo);
GLRow (const GLRow<DT>& anotherOne);
GLRow<DT>& operator= (const GLRow<DT>& anotherOne); //Make sure you do a$
int getNext();
int getDown();
DT& getInfo() const;
int setNext(int n);
int setDown(int d);
int setInfo (const DT& x);
~GLRow(); //destructor
};
Вот определение класса для моего ArrayGLL:
//************************************************************************************
// ARRAYGLL CLASS
//************************************************************************************
template <class DT>
class ArrayGLL; //class prototype
template <class DT>
ostream& operator <<(ostream& s, ArrayGLL<DT>& oneGLL);
template <class DT>
class ArrayGLL {
friend ostream& operator<< <DT>(ostream& s, ArrayGLL<DT>& OneGLL);
protected:
GLRow<DT>* myGLL;
int maxSize; //Maximum size of the array $
int firstElement;
int firstFree;
public:
ArrayGLL ();
ArrayGLL (int size);
ArrayGLL (ArrayGLL<DT>& anotherOne);
ArrayGLL<DT>& operator= (ArrayGLL<DT>& anotherOne);
void display (); //display in parenthesis for$
int find (DT& key); //return the index position $
void findDisplayPath (DT& Key); // as you travel through the$
int noFree (); //return the number of free $
int size (); //return the number of eleme$
int parentPos(DT& Key); // provide the location of t$
GLRow<DT>& operator [] (int pos); //return the GLRow that is i$
int getFirstFree();
int getFirstElement();
void setFirstFree (int pos);
void setFirstElement (int pos);
~ArrayGLL (); //destructor
};
Наконец, это мой конструктор для объекта ArrayGLL:
template <class DT>
ArrayGLL<DT>::ArrayGLL()
{
maxSize = 10;
firstElement = 0;
firstFree = 0;
myGLL = new GLRow<DT>[10];
}
Итак, как вы можете видеть Мне нужен массив объектов GLRow, но я не уверен, где я иду не так. Когда я вызываю конструктор, я получаю недопустимую ошибку указателя: «ошибка в« main »: munmap_chunk (): неверный указатель: 0x00000000014c3038 ***»