|
Boost : |
From: Dave Abrahams (abrahams_at_[hidden])
Date: 1999-12-10 23:58:10
Ed Brey wrote:
> "Moore, Paul" wrote:
>>
>> Here is the complete version of my rational numbers class. I believe that it
>> now covers everything which has been discussed here, as well as including
>> some documentation. The supplied "example.cpp" doubles as sample code and a
>> simple test case.
Good job; I know this will be useful!
> First, one interface issue:
>
> Should there be an assign function, similar to what std::string has.
> This would allow you to reassign a rational without creating a
> temporary. For example, in the read from stream operator, code would
> change from
> r = rational<Int>(n, d);
> to
> r.assign(n, d);
I don't think this would hurt.
> 2. The destructor defined in bad_rational is superfluous. As an
> example, std::domain_error defines no destructor.
But what's really missing is an implementation of the what() function!
> 3. Of the base classes of rational, only less_than_comparable is
> public; all others are private.
I would like to point out once again that it would be OK to make all of
these base classes private. In fact, it makes the code quite a bit cleaner.
There's no question of inheriting public interface from them.
Also,
This is surely illegal, no?
#ifdef BOOST_NO_STDC_NAMESPACE
namespace std { using ::abs; }
#endif
On formatting:
I would like to see all inline functions removed from the class body; it
makes the interface so much clearer, and there'd be room for (gasp!)
comments.
I'd also like to see a blank line between member functions.
I'd also *really* like to see the class start with its public interface
instead of its private data members.
Regards,
Dave
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk