For no particular reason I just wrote my own stack template, neat little thing that I did to get some experience in areas that I either have never worked, or have done little work. One of the neat features I added was the ability to push and pop using the << and >> operators. All that aside:
When I went to test the class it compiled fine but then the linker choked with an "undefined external identifier" error on my push and pop routines... Since the "undefined external identifier" error is usually do to scope a went took them out of my .cpp file and put them inside the header file (technically inside the class declaration). To my surprise this fixed the error. None of my other functions need to be in there, just those two.
Question is why?
Here is how they were defined inside the .cpp file:
CODE
template <class T>
T ADTStack<T>::pop()
{
T ret;
if (iStackPointer != -1)
{
ret=TheStack[iStackPointer--];
}
return ret;
}
template <class T>
bool ADTStack<T>::push()
{
bool ret = false;
if (iStackPointer + 1 < iStackSize)
{
TheStack[++iStackPointer] = oItem;
ret = true;
}
return ret;
}
I ask this because this is only my second or third template class and I wonder if I did something wrong.