scalar deleting destructor linker issue
***********this is the Node.h file****************
template < class T>
class node
{
public:
T info; //member to store the data of the node
node
node(); //default constructor
node(T); //constructor with 1 parameter for data
~node(); //destructor
};
***********eof****************
***********this is the Node.cpp file****************
#include “Node.h”
//default constructor
template
node
info (new T),
next (NULL)
{}
//constructor with 1 parameter for data
template
node
{
info = new T data;
next = NULL;
}
// destructor
template
node
{ delete info; }
***********eof****************
***********this is the Stack.h file****************
#include “Node.h”
template < class T>
class Stack{
private:
node
int count; // keep track the number of items on stack
public:
Stack(void); //the “constructor”
~Stack(); //class destructor – free up used memory
void push(T a); // add (push) the given item a onto the stack
T pop(void); // returns and removes the top item on the stack
T peek(void); // returns the top item without removing it from stack
bool isEmpty() const; //return true if the stack has no elements
int get_count(); // returns the count of nodes in the stack
};
***********eof****************
***********this is the Stack.cpp file****************
#include “Stack.h”
//default constructor
template
Stack
{
top = 0;
count = 0;
}
//accessor for the count member
template
int Stack
{ return count; }
//method to determine if the list is empty
template
bool Stack
{
if (count == 0)
return true;
else
return false;
}
// destructor
template
Stack
{
while (!isEmpty())
pop();
}
//method to pop off the top item of the list,
//returning its value and removing it from the list
template
T Stack
{
if (isEmpty())
throw Underflow(); //if the stack is empty, throw underflow
node
top = top->next; //set the top to the next node in the stack
T storedValue = topHolder->info; //store the value of the old top node
delete topHolder; //delete the old top node
–count; //decrement the number of nodes in the stack
return storedValue; //return the value of the node that was popped
}
//method to return the data of the top node without
//removing it from the list
template
T Stack
{
if (isEmpty())
throw Underflow(); //if the stack is empty, throw underflow
return top->info; //return the info stored in the top node
}
//method to push a new node onto the top of the list
template
void Stack
{
node newTop = new node(a); //allocate and construct the new node for the top of the stack
if (!isEmpty())
newTop.next = top->next; //set the next member of the new node to the current top node on the stack
top = *newTop; //set the top member of the stack to a pointer to the newTop
++count; //increment the number of nodes in the stack
}
***********eof****************
***********main.cpp****************
/*#include
#include
#include
using namespace std;
*/
//#include “Stack.h”
#include “Stack.cpp”
int main()
{
Stack
return 0;
}
***********eof***********
if anyone has any ideas I would be very grateful =)
~SunnyD
View post:
scalar deleting destructor linker issue
18