读书人

求写一个重载操作符+=实现与C++中st

发布时间: 2012-04-23 13:17:38 作者: rapoo

求写一个重载操作符+=,实现与C++中string类中的相同功能,谢谢大家~
请大家帮我写一个重载操作符+=,实现与C++中string类中的相同功能,效率越高越好。
我是一初学者,希望能多加注释,谢谢大家帮忙!

[解决办法]
直接调用append函数

C/C++ code
_Myt& __CLR_OR_THIS_CALL operator+=(const _Myt& _Right)        {    // append _Right        return (append(_Right));        }_Myt& __CLR_OR_THIS_CALL append(const _Myt& _Right,        size_type _Roff, size_type _Count)        {    // append _Right [_Roff, _Roff + _Count)        if (_Right.size() < _Roff)            _String_base::_Xran();    // _Roff off end        size_type _Num = _Right.size() - _Roff;        if (_Num < _Count)            _Count = _Num;    // trim _Count to size        if (npos - _Mysize <= _Count || _Mysize + _Count < _Mysize)            _String_base::_Xlen();    // result too long        if (0 < _Count && _Grow(_Num = _Mysize + _Count))            {    // make room and append new stuff            _Traits_helper::copy_s<_Traits>(_Myptr() + _Mysize, _Myres - _Mysize,                _Right._Myptr() + _Roff, _Count);            _Eos(_Num);            }        return (*this);        } 

读书人网 >C++

热点推荐