Posted-Date: Sun, 8 Jun 1997 10:26:41 +0300 Message-ID: <01BB5524.FFB8B7E0@pl5.techno-link.com> From: "Alian Ltd." To: "'djgpp AT delorie DOT com'" Subject: RE: Template problem. Date: Sat, 8 Jun 1996 10:25:51 +0300 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8bit Precedence: bulk Try removing the 'void' inside the Stack destructor parameter list. I'm not sure if it's gonna help, but once I think I had common problem. Usually the destructors do not have parameter lists and some compilers 'scream' when they see this. BTW, why you need in NodeC destructor to make Prev=Next=NULL ? Is that necessary (anyway, you'll never use these member variables - you do not need to assign a value to them). Regards ! Dony -----Original Message----- From: Gregary J Boyles [SMTP:boylesgj AT lion DOT cs DOT latrobe DOT edu DOT au] Sent: Saturday, May 31, 1997 11:52 AM To: djgpp AT delorie DOT com Subject: Template problem. 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