Stack is a template class with a vector m_elem. Vector type is also template. So in main I am trying to push an int into the vector but it is showing undefined reference. No idea y is this happening. The program is as follows.
main file
int main()
{
Stack<int> intStack;
intStack.push(7);
return EXIT_SUCCESS;
}
.h file
template<class T>
class Stack
{
public:
void push(T const& elem);
protected:
private:
vector<T> m_elem;
};
.cpp file
template<class T>
void Stack<T>::push(T const& elem)
{
m_elem.push_back(elem);
}
Error showing is
undefined reference to Stack<int>::push(int const&)
Can someone please help me. Thanking You in advance.