Andre Poenitz <[EMAIL PROTECTED]> writes:
| Still leaking.
And not exception safe either?
Why didn't you use the approach I outlined in prev mail?
To be exception safe you need a third object to do the construction
in. After construction is finished you swap contends.
| +MathedArray::MathedArray(MathedArray const & array)
| +{
| + copy(array);
| +}
| +
| +
| +MathedArray & MathedArray::operator=(MathedArray const & array)
| +{
| + if (&array != this) {
| + destroy();
| + copy(array);
| + }
| + return *this;
| +}
| +
| +
| +void MathedArray::copy(MathedArray const & array)
| +{
| + // this "implementation" is obviously wrong: MathedIter should be
| + // implemented by MathedArray (not the other way round) but I think
| + // getting the _interface_ of MathedArray right is more important right
| + // now (Andre')
| +
| + // shallow copy
| + bf_ = array.bf_;
| + last_ = array.last_;
| +
| + // deep copy
| + // we'll not yet get exeption safety
| + MathedIter it;
| + it.SetData(this);
| + while (it.OK()) {
| + if (it.IsInset()) {
| + MathedInset * inset = it.GetInset();
| + inset = inset->Clone();
| + raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
| + }
| + it.Next();
| + }
| +}
MathedArray::MathedArray(MathedArray const & array)
{
// this "implementation" is obviously wrong: MathedIter should be
// implemented by MathedArray (not the other way round) but I think
// getting the _interface_ of MathedArray right is more important right
// now (Andre')
// shallow copy
bf_ = array.bf_;
last_ = array.last_;
// deep copy
// we'll not yet get exeption safety
// no, but we are trying...
MathedIter it;
it.SetData(this);
while (it.OK()) {
if (it.IsInset()) {
MathedInset * inset = it.GetInset();
inset = inset->Clone();
raw_pointer_insert(inset, it.getPos() + 1, sizeof(inset));
}
it.Next();
}
}
MathedArray & MathedArray::operator=(MathedArray const & array)
{
MathedArray tmp(array);
// destruction of the current contents is taken care
// by by the destructor after the swap.
swap(tmp);
return *this;
}
| +void MathedArray::swap(MathedArray & array)
| +{
| + std::swap(bf_, array.bf_);
vector already have a swap method, use that.
bf_.swap(aray.bf_);
Lgb