0

I'm making a queue with a linked list. The linked list is two classes and one struct, IList is an abstract class and List inherits from IList. It seems like I can't access my List class from my queue without weird errors.

template <typename T>
class IList{
public:
    virtual ~IList();
    virtual void add(const T& element) = 0;

    //all functions here are pure virtual
};



template <typename T>
class List : public IList<T>{
private:

    struct Node{
        T data;
        Node* next; 
    };

Node* current;
int nrOfElements;

public:
    List();
    ~List();
    List(const List& origObj);
    void operator=(const List& origObj);
    virtual void add(const T& element);
};


//class definition

All funktions in my List class works fine but when I try to access it from queue.h I get two errors

Error 1 error LNK2019: unresolved external symbol "public: virtual __thiscall IList::~IList(void)" (??1?$IList@H@@UAE@XZ) referenced in function __unwindfunclet$??0?$List@H@@QAE@ABV0@@Z$0

and

Error 2 error LNK1120: 1 unresolved externals

Queue inherits from IQueue and IQueue is an abstract class

template <typename T>
class Queue : public IQueue<T>{

private:
    List<T>* aList; //I can't access List via aList->

public:
    Queue();
    Queue(const Queue& origObj);
    void operator=(const Queue& origObj);
    virtual ~Queue();
    virtual void enqueue(const T& element);
    virtual T dequeue() const throw(...);
    virtual T& front() throw(...);
    virtual bool isEmpty() const;
};
Mallom
  • 47
  • 1
  • 6

1 Answers1

1

Virtual destructor must have implementation even if it is pure. See Why a pure virtual destructor needs an implementation So, you have to do

template <typename T>
class IList{
public:
    virtual ~IList();
    virtual void add(const T& element) = default;

    //all functions here are pure virtual
};

or

template <typename T>
class IList{
public:
    virtual ~IList();
    virtual void add(const T& element) = 0;

    //all functions here are pure virtual
};

template <typename T>
IList<T>::~IList(){}
Community
  • 1
  • 1
user2807083
  • 2,962
  • 4
  • 29
  • 37
  • why did you write default instead of = 0? – Mallom Apr 05 '16 at 12:25
  • Because destructor can't be pure virtual. Even if I make it =0 I must provide implementation. So I can either did it default or pure virtual but with additional implementation. And read link to other related question, there are more explanation. – user2807083 Apr 05 '16 at 12:34