繁体   English   中英

std::basic_string 特化

[英]std::basic_string specialization

我只需要从 std::basic_string 覆盖长度 function 因为它对于特定平台上的自定义 char 类型不正确。 这是当前的声明,比如说,CustomString

typedef STL::basic_string<CustomChar, STL::char_traits<CustomChar>, STL::allocator<CustomChar> > CustomString;

我需要一个 class,其行为与 CustomString 一样,但长度 function 已更改。

您需要专门化std::char_traits结构并覆盖其static size_t length(const char_type* s); function 做到这一点。

然后,您甚至不需要在实例化basic_string时指定所有模板参数。 以下定义应该足够了:

typedef std::basic_string<CustomChar> CustomString;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM