今天看了看C++中的模板,写了个简单的代码,然后分别用CodeBlocks和GNU/Linux上调试。在GNU/Linux上调试的时候犯了一个“超级低级”的错误,对自己无语了...废话不多讲了,直接上code:
代码完全没有问题的啊。不过后来编译的时候用错了编译器,郁闷....
/cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o: In function `__static_initialization_and_destruction_0':
/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/iostream:77: undefined reference to `std::ios_base::Init::Init()'
/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/iostream:77: undefined reference to `std::ios_base::Init::~Init()'
/cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o: In function `main':
/cygdrive/e/SourceCode/C++/ClassTemplate/main.cpp:9: undefined reference to `std::allocator::allocator()'
/cygdrive/e/SourceCode/C++/ClassTemplate/main.cpp:9: undefined reference to `std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'
/cygdrive/e/SourceCode/C++/ClassTemplate/main.cpp:9: undefined reference to `std::basic_string, std::allocator >::~basic_string()'
/cygdrive/e/SourceCode/C++/ClassTemplate/main.cpp:9: undefined reference to `std::basic_string, std::allocator >::~basic_string()'
/cygdrive/e/SourceCode/C++/ClassTemplate/main.cpp:9: undefined reference to `std::allocator::~allocator()'
/cygdrive/e/SourceCode/C++/ClassTemplate/main.cpp:9: undefined reference to `std::allocator::~allocator()'
/cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o: In function `Queue':
/cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:20: undefined reference to `std::cout'
/cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:20: undefined reference to `std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:20: undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:20: undefined reference to `std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o: In function `~Queue': cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:25: undefined reference to `std::cout'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:25: undefined reference to `std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:25: undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:25: undefined reference to `std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o:/cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:30: undefined reference to `std::basic_string, std::allocator >::operator=(std::basic_string, std::allocator > const&)'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o:/cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:31: undefined reference to `std::cout'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o:/cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:31: undefined reference to `std::basic_ostream >& std::operator<< , std::allocator >(std::basic_ostream >&, std::basic_string, std::allocator > const&)'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o:/cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:31: undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o:/cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:31: undefined reference to `std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o: In function `Queue': cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:18: undefined reference to `std::basic_string, std::allocator >::basic_string()' cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:20: undefined reference to `std::cout'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:20: undefined reference to `std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:20: undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:20: undefined reference to `std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:20: undefined reference to `std::basic_string, std::allocator >::~basic_string()'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o: In function `~Queue': cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:25: undefined reference to `std::cout' cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:25: undefined reference to `std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:25: undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:25: undefined reference to `std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:25: undefined reference to `std::basic_string, std::allocator >::~basic_string()'
cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:25: undefined reference to `std::basic_string, std::allocator >::~basic_string()'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o:/cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:31: undefined reference to `std::cout'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o:/cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:31: undefined reference to `std::basic_ostream >::operator<<(int)'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o:/cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:31: undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o:/cygdrive/e/SourceCode/C++/ClassTemplate/queue.h:31: undefined reference to `std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))'
cygdrive/c/DOCUME~1/meego/LOCALS~1/Temp/ccQWEhNY.o:main.cpp:(.eh_frame+0x12): undefined reference to `___gxx_personality_v0'
ld returned 1 exit status