我正在尝试使用模板类,当我在 LWS 的一个文件中编译它时,它可以工作:
(链接失效)~http://liveworkspace.org/code/a9c412a7e683439dfa35a9363749369d~
但是当我尝试编译它由 3 个文件组成时,
stack.h 第 4 到 21 行
stack.cpp 第 24 到 48 行
main.cpp 第 49 行到结束
当我尝试编译这 3 个文件时,我得到
Undefined symbols for architecture x86_64:
"Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::push(Node**, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
_main in ccCoizCT.o
"Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::top(Node*&)", referenced from:
_main in ccCoizCT.o
"Stack2<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::pop(Node*&)", referenced from:
_main in ccCoizCT.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
是的,我在 stack.cpp 和 main.cpp 文件中包含了 stack.h