From: boylesgj AT lion DOT cs DOT latrobe DOT edu DOT au (Gregary J Boyles) Newsgroups: comp.os.msdos.djgpp Subject: Template problem. Date: 31 May 1997 08:51:30 GMT Organization: Comp.Sci & Comp.Eng, La Trobe Uni, Australia Lines: 234 Distribution: world Message-ID: <5mooqi$k9v@lion.cs.latrobe.edu.au> NNTP-Posting-Host: lion.cs.latrobe.edu.au To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk What am I doing wrong with this friggin template class.? gxx -fno-implicit-templates test.cc test.o: In function `main': test.cc:15: undefined reference to `StackQueueC::StackQueueC(void)' test.cc:30: undefined reference to `StackQueueC::~StackQueueC(void)' void main() { StackQueueC S; } template class NodeC { public: // The node's data. T Data; // Pointer to the next and previous nodes. NodeC *Next,*Prev; // Constructor. NodeC() { Next=Prev=NULL; }; // Destructor. ~NodeC() { Next=Prev=NULL; }; }; template class StackQueueC { private: // The first and last node in the linked list. NodeC *First,*Last; // The number of nodes in the list. int NumNodes; public: // Constructor. StackQueueC(void); // Detsructor. ~StackQueueC(void); // Checks for an empty queue or stack. bool Empty(); // Stack functions. bool Pop(T &Data); bool Push(T &Data); // Queue functions. bool Enqueue(T &Data); bool Dequeue(T &Data); }; // Constructor. template StackQueueC::StackQueueC() { First=Last=NULL; NumNodes=0; } // Detsructor. template StackQueueC::~StackQueueC() { T Data; while (!Empty()) Pop(Data); } // Checks for an empty queue or stack. template bool StackQueueC::Empty() { return NumNodes==0; } // Stack functions. template bool StackQueueC::Pop(T &Data) { NodeC *Temp=NULL; bool Result=false; // If the stack is not empty. if (!Empty) { Temp=First; if (NumNodes==1) { Last=NULL; First=NULL; } else { First=Temp->Next; First->Prev=NULL; } Data=Temp->Data; delete Temp; NumNodes--; Result=true; } return Result; } template bool StackQueueC::Push(T &Data) { NodeC *Temp=NULL; bool Result=false; // Create a new node. Temp=new NodeC; // If successful then add the node to the stack. if (Temp) { Temp->Data=Data; NumNodes++; Result=true; if (Empty()) { Last=Temp; First=Temp; } else { Temp->Next=First; First->Prev=Temp; First=Temp; } } return Result; } // Queue functions. template bool StackQueueC::Enqueue(T &Data) { NodeC *Temp=NULL; bool Result=false; // Create a new node. Temp=new NodeC; // If successful then add the node to the queue. if (Temp) { Temp->Data=Data; NumNodes++; Result=true; if (Empty()) { Last=Temp; First=Temp; } else { Last->Next=Temp; Temp->Prev=Last; Last=Temp; } } return Result; } template bool StackQueueC::Dequeue(T &Data) { // Poping is the same as dequeuing return Pop(Data); } #endif