Hi all.
I am trying to write a template class queue for an "assignment" and I got stuck by what I think is a syntax error.
To be honest, the assignment was MUCH easier than that but after having it completed I thought to be interesting to explore new possibilities... here's why the " " :P
I have two template structures, slist and dlist, that are in fact nodes of single linked lists and double linked lists respectively, that can store data of any given type.
I have a template class, queue, in order to create queues with data organized either in Single or Double linked lists.
I am trying to write two different constructors, one to be run if the object is a queue based on a SLL data structure and one for object built upon the other struct. The reason is that I most likely will need to hande more specifically one or the other case, (e.g. the second pointer of the dll). It would be nice to understand the concept in order to differentiate some other funcion, too, but I bet that this constructor case will give me the start.
Here's what I have so far:
#include <iostream>
#include <string.h>
using std::cout;
using std::endl;
using std::cin;
template <class D>
struct slist {
public:
D data;
slist<D> *next;
};
template <class D>
struct dlist {
public:
D data;
dlist<D> *next;
dlist<D> *prev;
};
template <class S>
class queue {
S *start;
string name;
public:
queue(void);
~queue(void);
};
template <class D>
queue<slist<D> >::queue(void) {
start = new slist<D>;
cout << endl << "Constructor slist Test" << endl;
return;
}
template <class D>
queue<dlist<D> >::queue(void) {
start = new dlist<D>:
cout << endl << "Constructor dlist Test" << endl;
return;
}
template <class S>
queue<S>::~queue(void) {
delete start;
cout << endl << "Destructor Test" << endl;
return;
}
int main(void) {
queue<slist<int> > ob1;
cin.get();
return EXIT_SUCCESS;
}
How may I differentiate the constructors?
This code isn't compiling for the following reason, that I don't understand.
error: invalid use of incomplete type ‘class queue<slist<D> >’
error: declaration of ‘class queue<slist<D> >’
error: invalid use of incomplete type ‘class queue<dlist<D> >’
error: declaration of ‘class queue<dlist<D> >’
Thanks in advance for any help, and as usual sorry for my poor english, I Hope I explained myself anyway ^^"