Can't supply my own class as List<T> parameter (class not defined)

28 Views Asked by At

first of all, IDE (if it can be called IDE at all) I'm using is BC 3.1 from 1992 so a lot of you may, and should, avoid this question.

Now, my problem is that I've made a polymorphic LinkedList class and it compiled with no errors. However if I declare LinkedList object with my own class as a paremeter in that class' header file I get a compile error Undefined structure and Size of 'data' is unknown or zero . I know the reason behind this error - the size of the objects IVTEntry are unknown at the time of declaring LinkedList object with the IVTEntry as class parameter.

My question is if it's possible to avoid this error without changing the LinkedList to be mono-morphic (swapping out the T parameter for IVTEntry object) ? Bear in mind that this is 1992 IDE and it doesn't have (to my knowledge at least) the capability to schedule compilation on its own i.e. it follows the program structure.

Here are the relevant pieces of code:

LIST.H

#ifndef _LIST_DEF.H_
#define _LIST_DEF.H_
template <class T>
class ListElem {
private:
    T data;
    ListElem* next;
public:
    ListElem(T input);
    ~ListElem();
    void link(ListElem* nextElem);
        ListElem* getNext();
};
template <class T>
class LinkedList {
private:
    ListElem<T>* head;
    int count;
public:
    LinkedList(T head);
    ~LinkedList();
    void add(T data);
    void add(ListElem(T) node);
    void remove(int entry);
    ListElem<T>* pop();
    ListElem(T>* getHead();
}
#endif

LIST.CPP

#include "list.h"
template <class T>
ListElem<T>::ListElem(T data) {
    this->data = data;
}
template <class T>
ListElem<T>::~ListElem() {
    delete this->data;
    this->next=0;
}
template <class T>
void ListElem<T>::link(ListElem<T>* node) {
    this->next = node;
}
template<class T>
ListElem<T>* ListElem<T>::getNext() {
    return this->next;
}
template <class T>
LinkedList<T>::LinkedList(ListElem<T>* head) {
    this->head = head;
    this->head->link(0);
}
template <class T>
LinkedList<T>::LinkedList(T data) {
    this->head = new ListElem<T>(data);
    this->head->link(0);
}
template <class T>
LinkedList<T>::~LinkedList() {
    while(head != 0) {
        ListElem<T>* temp = head;
        head=head->getNext();
        delete temp;
    }
}
template <class T>
void LinkedList<T>::add(ListElem<T>* node) {
    if(this->head == 0) {
        this->head = node;
        this->head->link(0);
        return;
    }
    ListElem<T>* current = this->head;
    while(current->getNext() != 0) {
        //looking for the last one
        current = current->getNext();
    }
    current->link(node);
    node->link(0);
}
template <class T>
void LinkedList<T>::remove(int entry) {
    if(this->head ==0 || entry < 0) {
        return;
    }
    if(entry == 0) {
        ListElem<T>* temp = this->head;
        this->head = this->head->getNext();
        delete temp;
        return;
    }
    ListElem<T>* current = this->head;
    int i = 1;
    while(current !=0) {
        if(i == entry) {
            break;
        }
        i++;
        current = current->getNext();
    }
    if(i < count) {
        if(current->getNext() != 0 && current->getNext()->getNext() != 0) {
            ListElem<T>* temp = current->getNext();
            current.link(current->getNext()->getNext();
            delete temp;
        }
    }
}
template <class T>
ListElem<T>* LinkedList<T>::pop() {
    ListElem<T>* node = head;
    if(head != 0) {
        head = head->getNext();
    }
    return node;
}
template <class T>
ListElem<T>* LinkedList<T>::getHead() {
    return head;
}

IVT.H

#ifndef _IVT_DEF_
#define _IVT_DEF_
#include "main_eve.h"
class IVTEntry {
    friend class MainEvent;
private:
    short entryNumber;
    MainEvent* event;
    void interrupt (*routine)(...);
public:
    IVTEntry(short eventNo, void interrupt (*routinedef)(...));
    ~IVTEntry();
    short getEntryNumber();
    IVTEntry* getEntry(short eventNo);
    void interrupt (*original)(...);
    static LinkedList<IVTEntry> *eventList;
};
#endif
0

There are 0 best solutions below