I built a stack, and it runs fine is I put the main function in the stack.cpp file instead of using a seperate cpp file for main, but once I put main in its own file and #include my stack, it wont work
Error 1 error LNK2019: unresolved external symbol "public: __thiscall myStack<int>::myStack<int>(int)" (??0?$myStack@H@@QAE@H@Z) referenced in function _main C:\Users\Drola_000\Google Drive\C++\ADTStack\ADTStack\Source.obj ADTStack
heres my code
Header
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
template <class T>
class myStack
{
private:
int _top;
T *_pItems;
int _MAX;
public:
void push( T data );
T pop();
int getSize();
bool isEmpty() { return _top == -1; }
bool isFull() { return _top+1 == _MAX;}
myStack<T>(int size);
~myStack<T>(void);
};
If memory serves, you can't put the implementation of a template class in a separate file. Try removing stack.cpp and put its contents at the bottom of stack.h.
An often used convention is to put your templates implementation into a separate file called "stack.tpp". Then include it at the bottom of "stack.h" which contains the templates class specification.