我需要只覆盖std :: basic_string中的length函数,因为它对于特定平台上的自定义char类型不正确。这是当前声明,比方说CustomString
typedef STL::basic_string<CustomChar, STL::char_traits<CustomChar>, STL::allocator<CustomChar> > CustomString;
我需要一个行为CustomString的类,但是更改了length函数。
答案 0 :(得分:7)
您需要专门化std::char_traits
结构并覆盖其static size_t length(const char_type* s);
函数才能执行此操作。
然后在实例化basic_string
时甚至不需要指定所有模板参数。以下定义应该足够了:
typedef std::basic_string<CustomChar> CustomString;