- 论坛徽章:
- 0
|
用了一个小程序测,还是不行
#include "iostream"
#include "string"
using namespace std;
enum TestType { one = 't', two, three };
template<typename CharType>;
class TestClass
: public std::basic_string<CharType>;
{
public:
virtual void test(const CharType *test)
{
(*this).assign(test);
}
};
int main(void)
{
TestClass<TestType>; test;
TestType t = one;
test.test(&t);
// cout << test << endl;
return 0;
}
编译能通过,连接的时候出错,错误信息如下:
/tmp/ccXwDe9p.o(.text+0x9c): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccXwDe9p.o(.text+0xcb): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE6assignEPKS_+0x10): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::assign(TestType const*)':
: undefined reference to `std::char_traits<TestType>;::length(TestType const*)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE4_Rep10_M_destroyERKS2_+0x37): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_Rep::_M_destroy(std::allocator<TestType>; const& ':
: undefined reference to `std::allocator<char>;::deallocate(char*, unsigned)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE4_Rep10_M_destroyERKS2_+0x54): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_Rep::_M_destroy(std::allocator<TestType>; const& ':
: undefined reference to `std::allocator<char>;::~allocator [in-charge]()'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE4_Rep10_M_destroyERKS2_+0x6b): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_Rep::_M_destroy(std::allocator<TestType>; const& ':
: undefined reference to `std::allocator<char>;::~allocator [in-charge]()'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE4_Rep10_M_destroyERKS2_+0x8c): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_Rep::_M_destroy(std::allocator<TestType>; const& ':
: undefined reference to `__cxa_call_unexpected'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE6assignEPKS_j+0x23): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::assign(TestType const*, unsigned)':
: undefined reference to `std::__throw_length_error(char const*)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE6assignEPKS_j+0x146): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::assign(TestType const*, unsigned)':
: undefined reference to `std::char_traits<TestType>;::copy(TestType*, TestType const*, unsigned)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE6assignEPKS_j+0x16b): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::assign(TestType const*, unsigned)':
: undefined reference to `std::char_traits<TestType>;::move(TestType*, TestType const*, unsigned)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE15_M_replace_safeIPKS_EERS3_N9__gnu_cxx17__normal_iteratorIPS_S3_EESB_T_SC_+0x52): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;& std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_M_replace_safe<TestType const*>;(__gnu_cxx::__normal_iterator<TestType*, std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >; >;, __gnu_cxx::__normal_iterator<TestType*, std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >; >;, TestType const*, __gnu_cxx::__normal_iterator<TestType*, std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >; > ':
: undefined reference to `std::__throw_length_error(char const*)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE9_M_mutateEjjj+0x14d): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_M_mutate(unsigned, unsigned, unsigned)':
: undefined reference to `std::char_traits<TestType>;::copy(TestType*, TestType const*, unsigned)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE9_M_mutateEjjj+0x184): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_M_mutate(unsigned, unsigned, unsigned)':
: undefined reference to `std::char_traits<TestType>;::copy(TestType*, TestType const*, unsigned)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE9_M_mutateEjjj+0x197): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_M_mutate(unsigned, unsigned, unsigned)':
: undefined reference to `__cxa_begin_catch'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE9_M_mutateEjjj+0x1cf): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_M_mutate(unsigned, unsigned, unsigned)':
: undefined reference to `__cxa_rethrow'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE9_M_mutateEjjj+0x1da): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_M_mutate(unsigned, unsigned, unsigned)':
: undefined reference to `__cxa_end_catch'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE9_M_mutateEjjj+0x285): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_M_mutate(unsigned, unsigned, unsigned)':
: undefined reference to `std::char_traits<TestType>;::move(TestType*, TestType const*, unsigned)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE13_S_copy_charsEPS_PKS_S6_+0x1c): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_S_copy_chars(TestType*, TestType const*, TestType const*)':
: undefined reference to `std::char_traits<TestType>;::copy(TestType*, TestType const*, unsigned)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE4_Rep9_S_createEjRKS2_+0x19): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_Rep::_S_create(unsigned, std::allocator<TestType>; const& ':
: undefined reference to `std::__throw_length_error(char const*)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE4_Rep9_S_createEjRKS2_+0xd7): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_Rep::_S_create(unsigned, std::allocator<TestType>; const& ':
: undefined reference to `std::allocator<char>;::allocate(unsigned, void const*)'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE4_Rep9_S_createEjRKS2_+0xf1): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_Rep::_S_create(unsigned, std::allocator<TestType>; const& ':
: undefined reference to `std::allocator<char>;::~allocator [in-charge]()'
/tmp/ccXwDe9p.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE4_Rep9_S_createEjRKS2_+0x10e): In function `std::basic_string<TestType, std::char_traits<TestType>;, std::allocator<TestType>; >;::_Rep::_S_create(unsigned, std::allocator<TestType>; const& ':
: undefined reference to `std::allocator<char>;::~allocator [in-charge]()'
/tmp/ccXwDe9p.o(.gnu.linkonce.r._ZTI9TestClassI8TestTypeE+0x0): undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/tmp/ccXwDe9p.o(.gnu.linkonce.r._ZTISbI8TestTypeSt11char_traitsIS_ESaIS_EE+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
/tmp/ccXwDe9p.o(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status |
|