在GNU实施std::string
,其_S_empty_rep_storage
被定义为:为什么std :: string的空rep是这样的?
template<typename _CharT, typename _Traits, typename _Alloc>
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
(sizeof(_Rep_base) + sizeof(_CharT) + sizeof(size_type) - 1)/sizeof(size_type)
];
为什么在size_type
而不是简单地char
来定义?为什么不定义为:
template<typename _CharT, typename _Traits, typename _Alloc>
_CharT
basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[
sizeof(_Rep_base) + sizeof(_CharT)
];
?
FYI:我问的原因是因为我实现我自己的字符串类 (即有std::string
不符合要求不同) 所以我想了解尽可能多的关于如何std::string
已实施。
因为结果是不一样的? – 2010-11-25 01:38:22
“,而不是简单的字符”< - 你的意思是说“而不是简单_CharT”在那里? – 2010-11-25 10:25:25