"Josephine Schafer" <no****************@hotmail.com> wrote in message
news:br************@ID-192448.news.uni-berlin.de...
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote in message
news:br*********@news.freedom2surf.net...
"Josephine Schafer" <no****************@hotmail.com> wrote in message
news:br************@ID-192448.news.uni-berlin.de...
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote in message
news:br**********@news.freedom2surf.net...
> I have had a look through the FAQ and found that if I am using a
class > template then I need an argument list. I have tried to add this but
it is > not quite working - i.e. it doesnt compile. My code is below, could
> somebody please point me in the right direction?
> Thanks
> Allan
>
>
>
> #include <iostream>
>
> template<typename generic>
>
> class Node
> {
> public:
> Node();
> Node(char xiType);
> virtual ~Node();
>
> void SetNextLink(Node *xiNode){NextNode = xiNode;}
> void SetPrevLink(Node *xiNode){PrevNode = xiNode;}
>
> Node *GetPrevLink(){return PrevNode;}
> Node *GetNextLink(){return NextNode;}
>
> void SetData(generic *xiData){Data = xiData;}
> generic *GetData(){return Data;}
>
> private:
> Node *NextNode;
> Node *PrevNode;
>
> generic *Data;
>
> bool Tail;
> bool Head;
> };
>
> Node<int> NodeInt;
> Node<float> NodeFloat;
> Node<double> NodeDouble;
> Node<char> NodeChar;
>
What's the error message?
It compiles fine on Comeau online.
The error is when I try to use one of the above methods, in my
DoubleList.h I have the following line
Node *GetLastNode(){return mTail->GetPrevLink();}
And the error message is
"f:\Documents and Settings\Allan\My
Documents\Progs\QueueStack\DoubleList.h(22): error C2955: 'Node' : use
of class template requires template argument list"
The error messages speak the reply for you.
Node is NOT a class but a class template.
So you can't return pointer to Node.
Instead Node<T> is a concrete class...assuming T as the template
parameter.
So, to access it outside the class-
template<typename T>
Node<T> *Node<T>::GetPrevLink(){return PrevNode;}
HTH,
J.Schafer
Thanks that did, I am trying to implement a generic stack and queue. I am
testing them out using the following code:
Stack<int> *lIntStack;// instantiate a new Stack of ints
Stack<double> *lDblStack;// instantiate a new Stack of doubles
Queue<char> *lCharQueue;// instantiate a new Queue of chars
lIntStack = new Stack<int>();// allocate memory to stack of ints
lDblStack = new Stack<double>();// allocate memory to stack of doubles
lCharQueue = new Queue<char>();// allocate memory to queue of chars
I am getting a compiler error in my Stack.cpp. The code around the error
is:
#include <iostream>
#include "Stack.h"
Stack::Stack()
{
mDataList = NULL;
mDataList = new DoubleList();
if (!mDataList)
return;
}
And my error is:
"f:\Documents and Settings\Allan\My Documents\Progs\QueueStack\Stack.cpp(4):
error C2955: 'Stack' : use of class template requires template argument
list"
I tried to make this Stack::Stack<generic>() but that didnt work - it
complains that its an undeclared identifier.
I am aware that my use of "new DoubleList" is going to require an arguemnet
aswell, but unsure of how to do it.
Where am I going wrong?
Thanks
Allan