Re: Abi string class


Subject: Re: Abi string class
From: Tim Allen (rita_tim@tpg.com.au)
Date: Thu Feb 01 2001 - 04:47:39 CST


On 2001.02.01 20:27:27 +1100 Sam TH wrote:
>> > value). To fix this we would have to forbid anything but the default
> > constructor, and we would have to write assignment as
> >
> > if (!s1.assign("bar"))
> >
> > I traded safety for readability. If this turns out to be an issue of
> > controversy I'll do it the "safe" way, but it would hurt readability
> much
> > IMO.
>
> This class looks excellent, but I have one question, which probably
> stems from my lack of C++ experience:
>
> If it would be possible to have a safer class by using
> s1.assign("foo"), why can't we simply overload operator() to be
> exactly the same function that assign would be?

The point is you need to know if it failed, eg we ran out of memory. A
function can return a bool, yes or no. An operator or constructor has other
constraints about what it can return, so you need to be able to trap
exceptions in that case. Look carefully at Mike's example again.
operator= has to return a reference to the result of assignment; it can't
return anything that tells you about success or failure.

> There's probably something big I'm missing here.
>
> Other than that, it looks cool.
>
> sam th

Tim

-- 
-----------------------------------------------------------
Tim Allen             http://www4.tpg.com.au/users/rita_tim/
tim@proximity.com.au  rita_tim@tpg.com.au



This archive was generated by hypermail 2b25 : Thu Feb 01 2001 - 04:47:32 CST