I use the following command:
g++ -std=c++11 main.cpp stack.cpp -o main
and then I get
main.cpp:(.text+0x11): undefined reference to `Stack<int>::Stack()'
main.cpp:(.text+0x1d): undefined reference to `Stack<std::string>::Stack()'
main.cpp:(.text+0x2e): undefined reference to `Stack<int>::push(int)'
main.cpp:(.text+0x3f): undefined reference to `Stack<int>::push(int)'
main.cpp:(.text+0x73): undefined reference to `Stack<std::string>::push(std::string)'
main.cpp:(.text+0xbf): undefined reference to `Stack<std::string>::push(std::string)'
main.cpp:(.text+0xe3): undefined reference to `Stack<std::string>::size() const'
main.cpp:(.text+0x119): undefined reference to `Stack<std::string>::top()'
collect2: error: ld returned 1 exit status
But if I change the line '#include "stack.h"' in main.cpp to '#include "stack.cpp"', it works OK.
Can someone please tell my why? And what is wrong in?