I don't understand where my coding is wrong. These are the errors I am getting when I debug: Error 2 error LNK2019: unresolved external symbol "public: bool __thiscall linkedStackType<int>::operator==(class linkedStackType<int> const &)" (??8?$linkedStackType@H@@QAE_NABV0@@Z) referenced in function _main E:\Chapter7a\Chapter7a\Chapter7a\Chapter7a.obj Chapter7a
Warning 1 warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification E:\Chapter7a\Chapter7a\Chapter7a\Chapter7a.obj Chapter7a
//Header File: linkedStack.h
#ifndef H_StackType
#define H_StackType
#include <iostream>
#include <cassert>
#include "stackADT.h"
usingnamespace std;
//Definition of the node
template <class Type>
struct nodeType
{
Type info;
nodeType<Type> *link;
};
template <class Type>
class linkedStackType : public stackADT<Type>
{
public:
const linkedStackType<Type>& operator=
(const linkedStackType<Type>&);
booloperator==(const linkedStackType<Type>&);
bool isEmptyStack() const;
bool isFullStack() const;
void initializeStack();
void push(const Type& newItem);
Type top() const;
void pop();
linkedStackType();
linkedStackType(const linkedStackType<Type>& otherStack);
~linkedStackType();
void reverseStack(linkedStackType<Type> &);
private:
nodeType<Type> *stackTop; //pointer to the stack
void copyStack(const linkedStackType<Type>& otherStack);
};
//Default constructor
template <class Type>
linkedStackType<Type>::linkedStackType()
{
stackTop = NULL;
}
template <class Type>
bool linkedStackType<Type>::isEmptyStack() const
{
return(stackTop == NULL);
} //end isEmptyStack
template <class Type>
bool linkedStackType<Type>::isFullStack() const
{
returnfalse;
} //end isFullStack
template <class Type>
void linkedStackType<Type>::initializeStack()
{
nodeType<Type> *temp; //pointer to delete the node
while (stackTop != NULL) //while there are elements in
//the stack
{
temp = stackTop; //set temp to point to the
//current node
stackTop = stackTop->link; //advance stackTop to the
//next node
delete temp; //deallocate memory occupied by temp
}
} //end initializeStack
template <class Type>
void linkedStackType<Type>::push(const Type& newElement)
{
nodeType<Type> *newNode; //pointer to create the new node
newNode = new nodeType<Type>; //create the node
newNode->info = newElement; //store newElement in the node
newNode->link = stackTop; //insert newNode before stackTop
stackTop = newNode; //set stackTop to point to the
//top node
} //end push
template <class Type>
Type linkedStackType<Type>::top() const
{
assert(stackTop != NULL); //if stack is empty,
//terminate the program
return stackTop->info; //return the top element
}//end top
template <class Type>
void linkedStackType<Type>::pop()
{
nodeType<Type> *temp; //pointer to deallocate memory
if (stackTop != NULL)
{
temp = stackTop; //set temp to point to the top node
stackTop = stackTop->link; //advance stackTop to the
//next node
delete temp; //delete the top node
}
else
cout << "Cannot remove from an empty stack." << endl;
}//end pop
template <class Type>
void linkedStackType<Type>::copyStack
(const linkedStackType<Type>& otherStack)
{
nodeType<Type> *newNode, *current, *last;
if (stackTop != NULL) //if stack is nonempty, make it empty
initializeStack();
if (otherStack.stackTop == NULL)
stackTop = NULL;
else
{
current = otherStack.stackTop; //set current to point
//to the stack to be copied
//copy the stackTop element of the stack
stackTop = new nodeType<Type>; //create the node
stackTop->info = current->info; //copy the info
stackTop->link = NULL; //set the link field of the
//node to NULL
last = stackTop; //set last to point to the node
current = current->link; //set current to point to
//the next node
//copy the remaining stack
while (current != NULL)
{
newNode = new nodeType<Type>;
newNode->info = current->info;
newNode->link = NULL;
last->link = newNode;
last = newNode;
current = current->link;
}//end while
}//end else
} //end copyStack
//copy constructor
template <class Type>
linkedStackType<Type>::linkedStackType(
const linkedStackType<Type>& otherStack)
{
stackTop = NULL;
copyStack(otherStack);
}//end copy constructor
//destructor
template <class Type>
linkedStackType<Type>::~linkedStackType()
{
initializeStack();
}//end destructor
//overloading the assignment operator
template <class Type>
const linkedStackType<Type>& linkedStackType<Type>::operator=
(const linkedStackType<Type>& otherStack)
{
if (this != &otherStack) //avoid self-copy
copyStack(otherStack);
return *this;
}//end operator=
template <class Type>
void linkedStackType<Type>::reverseStack(linkedStackType<Type>& right)
{
right.initializeStack();
nodeType<Type> *temp = this->stackTop;
while (temp != NULL)
{
right.push(temp->info);
temp = temp->link;
}
}
#endif
#include "stdafx.h"
#include "linkedStack.h"
usingnamespace std;
int main()
{
cout << "This program reverses elements of a stack onto another stack" << endl;
linkedStackType<int> stack1;
linkedStackType<int> stack2;
cout << "Inserting elements 5, 10, and 15 into both the stacks" << endl;
for
(int i = 5; i < 50; i += 5)
stack1.push(i);
stack2 = stack1;
//check for equality of the stacks
if
(stack1 == stack2)
cout << "The two stacks are equal";
else
cout << "The tow stacks are unequal";
//reverse the stack on to another stack
cout << "Reversing the stack onto another stack";
stack1.reverseStack(stack2);
//check for equality of the stacks
if
(stack1 == stack2)
cout << "The two stacks are equal";
else
cout << "The tow stacks are unequal";
//pritn the elements of the stack 1
cout << "The elements in the first stack are: ";
while (!stack1.isEmptyStack())
{
cout << stack1.top() << " ";
stack1.pop();
}
//print the elements of stack2
cout << "The elements in the second stack are: ";
while (!stack2.isEmptyStack())
{
cout << stack2.top() << " ";
stack2.pop();
}
system("PAUSE");
return 0;