Arrayhandler クラスを作成していて、 and をオーバーロードする必要がoperator+
ありoperator++
ます。
operator++
でオーバーロードするのは良い考えoperator+(1)
ですか? 私が知る限り( size_tは_current = _pointee + i
どこですか)変更されないため、無限ループが発生します。なんで?そのような方法でポインタを追加するのは正しいですか?i
_current
class ArrayHandler
{
private:
size_t _size;
Pointee *_pointee;
Pointee *_end;
mutable Pointee *_current;
....
}
私の中心:
template <typename Pointee>
ArrayHandler<Pointee>::ArrayHandler(size_t size):
_size(size), _pointee(new Pointee[_size]), _end(_pointee+_size), _current(_pointee)
{};
オペレーター+ :
ArrayHandler<Pointee>& ArrayHandler<Pointee>::operator+(size_t i)
{
if (!defined())
throw MisUse(undefArray, 0);
if ( _pointee + i > _end || _pointee + i < _pointee)
throw MisUse(badIndex, i);
_current = _pointee + i;
return *this;
};
演算子++ :
template <typename Pointee>
ArrayHandler<Pointee>& ArrayHandler<Pointee>::operator++()
{
if (!defined())
throw MisUse(undefArray, 0);
if ( stop() )
throw MisUse(badIndex, 0);
++_current;*/
this->operator+(1);
return *this;
};
無限実行を引き起こす while ループ:
while (!ar3.stop())
{
++ar3;
++count;
}
とstop()
方法:
bool stop() const {return _current ==_end;}
アップデート:
無限 while ループの理由は、operator++ を operator+ で実装したためです。私の場合、毎回 _current を start+1 に変更したため、2 回目の反復の後、_current は変更されませんでした。その都度start+1でRESETを繰り返していました。
彼ら!!