#ifndef H_myStack
#define H_myStack
#include <iostream>
#include <cassert>
usingnamespace std;
template<class Type>
publicclass stackType
{
public:
const stackType<Type>& operator=(const stackType<Type>&);
//overload the assignment operator =
void initalizeStack();
//Function to intialize the stack to an empty state
//Postcondtion: stackTop = 0;
bool isEmptyStack();
//Function to determine if the stack is empty
//Postcondition: Returns true when stack is empty
// else, it returns false
bool isFullStack();
//Function to determins if the stack is full
//Postcindition: Returns true if the stack is full
// else, it returns false
void destroyStack();
//Function to remove everything from the stack
//Postcondition: stackTop = 0;
void push(const Type& newItem);
//Function to add an item to the top of the stack
//Precondition: The stack exists and is not full
//Post condition: The stack is changed and newItem is on top
Type top();
/*Function to return the top element of the stack
Precondition: the stack exists and is not empty
PostCondition: if the stack is empty, the program terminates,
else the top item of the stack is returned
*/
void pop();
/*Function to remove the top item of the stack
Precondition: the stack exists and is not empty
Postcondition: the stack is changed, and the top item is removed
*/
stackType(int stackSize = 100);
/*constructor
creates an array of the size stackSize to hold
the stacks items. The default is 100.
Postcondition: The variable list contains the base address of the array
stackTop = 0; and maxStackSize = stackSize;
*/
stackType(const stackType<Type>& otherStack);
/*copy constructor*/
~stackType();
/*destructor
removes all the items from the stack
postcondition: the array (list) holding the stack's items is deleted
*/
private:
int maxStackSize;//variable to store the maximum stack size
int stackTop; //variable to point to the top of the stack
Type *list; //Pointer to the array that holds the stack items
void copyStack(const stackType<Type>& otherStack);
/*Function to make a copy of the other stack
PostCondition: a copy of otherStack is created and
assigned to this stack*/
};
#endif;
#include <iostream>
#include "myStack.h"
usingnamespace std;
int main()
{
stackType<int> intStack(50);//creates a stack of type int with 50 places
stackType<int> tempStack; //creates a temp stack of type int to store intStack elements
intStack.push(23);
intStack.push(45);
intStack.push(38);
tempStack = intStack; //copy intStack into tempStack
cout << "tempStack element: ";
while (!tempStack.isEmptyStack())
{
cout << tempStack.top()<< " ";
tempStack.pop();
}
cout << endl;
cout << "The top element of intStack: " << intStack.top() << endl;
return 0;
}
And here are my errors
Errors
------ Build started: Project: example 7-1, Configuration: Debug Win32 ------
Compiling...
myStackIMP.cpp
Linking...
main.obj : error LNK2028: unresolved token (0A0002B1) "public: class stackType<int> const & __thiscall stackType<int>::operator=(class stackType<int> const &)" (??4?$stackType@H@@$$FQAEABV0@ABV0@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2028: unresolved token (0A0002B2) "public: bool __thiscall stackType<int>::isEmptyStack(void)" (?isEmptyStack@?$stackType@H@@$$FQAE_NXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2028: unresolved token (0A0002B3) "public: void __thiscall stackType<int>::push(int const &)" (?push@?$stackType@H@@$$FQAEXABH@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2028: unresolved token (0A0002B4) "public: int __thiscall stackType<int>::top(void)" (?top@?$stackType@H@@$$FQAEHXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2028: unresolved token (0A0002B5) "public: void __thiscall stackType<int>::pop(void)" (?pop@?$stackType@H@@$$FQAEXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2028: unresolved token (0A0002B6) "public: __thiscall stackType<int>::stackType<int>(int)" (??0?$stackType@H@@$$FQAE@H@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2028: unresolved token (0A0002B7) "public: __thiscall stackType<int>::~stackType<int>(void)" (??1?$stackType@H@@$$FQAE@XZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2019: unresolved external symbol "public: __thiscall stackType<int>::~stackType<int>(void)" (??1?$stackType@H@@$$FQAE@XZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall stackType<int>::pop(void)" (?pop@?$stackType@H@@$$FQAEXXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2019: unresolved external symbol "public: int __thiscall stackType<int>::top(void)" (?top@?$stackType@H@@$$FQAEHXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2019: unresolved external symbol "public: bool __thiscall stackType<int>::isEmptyStack(void)" (?isEmptyStack@?$stackType@H@@$$FQAE_NXZ) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2019: unresolved external symbol "public: class stackType<int> const & __thiscall stackType<int>::operator=(class stackType<int> const &)" (??4?$stackType@H@@$$FQAEABV0@ABV0@@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall stackType<int>::push(int const &)" (?push@?$stackType@H@@$$FQAEXABH@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
main.obj : error LNK2019: unresolved external symbol "public: __thiscall stackType<int>::stackType<int>(int)" (??0?$stackType@H@@$$FQAE@H@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
C:\Documents and Settings\William\My Documents\Visual Studio 2008\Projects\example 7-1\Debug\example 7-1.exe : fatal error LNK1120: 14 unresolved externals
Build log was saved at "file://c:\Documents and Settings\William\My Documents\Visual Studio 2008\Projects\example 7-1\example 7-1\Debug\BuildLog.htm"
example 7-1 - 15 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I don't think it is because I did not include a library, and I am using a CLR Empty project. Should I have used just a simple Empty Project?