BCB5和BCB6中的traits重载问题
下面这个程序,是重载(继承)了char_traits从而实现对字符串的忽略大小写排序的例子。在BCB6下编译运行都正常。
-----------------------------------------
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <ctype.h> //for toupper function
using namespace std;
struct NoCase_char_traits : public char_traits<char>
{
static bool eq(const char_type& c1,const char_type& c2) { return toupper(c1) == toupper(c2); };
static bool lt(const char_type& c1,const char_type& c2) { return toupper(c1) < toupper(c2); };
static int compare(const char* s1, const char* s2, size_t n)
{
for (size_t i=0; i<n; ++i)
{
if (!eq(s1[i],s2[i]))
{
return lt(s1 [i],s2[i])?-1:1;
}
}
return 0;
}
static const char* find(const char* s, size_t n, const char& c)
{
for (size_t i=0; i<n; ++i)
{
if (eq(s[i],c))
{
return &(s[i]);
}
}
return 0;
}
};
int main()
{
typedef basic_string<char, NoCase_char_traits> mystring ;
vector<mystring> m_tempList;
m_tempList.push_back("a");
m_tempList.push_back("AB");
m_tempList.push_back("Bcd");
m_tempList.push_back("bDe");
sort(m_tempList.begin(), m_tempList.end(), less<mystring>());
for(int i = 0; i < m_tempList.size(); ++i)
{
cout << m_tempList[i].c_str() << endl;
}
system("PAUSE");
return 0;
}
----------------------------------
但是用bcb5编译,则会出现以下错误(Link Error):
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external 'std::basic_string<char, NoCase_char_traits, std::allocator<char> >::__nullref' referenced from G:\TEMP\1.OBJ
Error: Unresolved external 'std::basic_string<char, NoCase_char_traits, std::allocator<char> >::basic_string<char, NoCase_char_traits, std::allocator<char> >(const char *, const std::allocator<char>&)' referenced from G:\TEMP\1.OBJ
Error: Unresolved external 'std::basic_string<char, NoCase_char_traits, std::allocator<char> >::__getRep(unsigned int, unsigned int)' referenced from G:\TEMP\1.OBJ
Error: Unresolved external 'std::basic_string<char, NoCase_char_traits, std::allocator<char> >::operator =(const std::basic_string<char, NoCase_char_traits, std::allocator<char> >&)' referenced from G:\TEMP\1.OBJ
Error: Unresolved external 'std::basic_string<char, NoCase_char_traits, std::allocator<char> >::compare(unsigned int, unsigned int, const char *, unsigned int) const' referenced from G:\TEMP\1.OBJ
显然这是RW STL和STLport的版本问题。
但这个写法是Juttis在《C++标准程序库》里演示的标准写法,我想知道在BCB5里,应该如何写这个char_traits?