|
Boost : |
From: Moore, Paul (paul.moore_at_[hidden])
Date: 2000-06-23 05:21:53
From: Mark Rodgers [mailto:mark.rodgers_at_[hidden]]
> rational/rational_example.cpp
>
> The problems are a bit deeper. If anyone is interested I've put
> a rational.hpp with workarounds in the vault in
>
> http://www.egroups.com/files/boost/Rational+Borland/rational.hpp
>
> I don't know if this will break any other compilers. I did test
> it with MSVC 6 and it was still OK, and that was the only one
> on Beman's table that had worked previously. Who knows - it might
> now work with more.
This version has
// Absolute value
friend rational<int_type> abs(const rational<int_type> &r)
{ ... }
defined inside the class. As far as I'm aware, it's not valid to define a
friend function inline within a class, and even if it is, it breaks MSVC.
See the standard:
[9.3.1] Functions declared in the definition of a class, excluding those
declared with a friend specifier (11.4), are called member functions of that
class.
[9.3.2] A member function may be defined (8.4) in its class definition
By implication, friends aren't members, and so may not be defined in the
class definition. [Technically, my logic is not 100% right here, but the
intent is clear].
I've included all the other changes you made, and looking at abs() it
doesn't actually need to be a friend (due to the presence of numerator() and
denominator()), so I've made it a normal non-friend function, which should
avoid the issue in any case.
I've also incorporated some changes from Beman.
The resulting version compiles and gives the expected results on MSVC 6,
SP3.
I've included a workaround for the mingw lack of <limits> in
rational_example.cpp, but mingw still breaks with
boost\rational.hpp: In function `class boost::rational<int>
boost::abs<int>(const boost::rational<int> &)':
rational_example.cpp:65: instantiated from here
boost\rational.hpp:311: no matching function for call to `abs (int)'
Does any mingw/gcc expert know what the problem is? I haven't a clue :-(
Borland (the free command line compiler 5.5) goes boom in operators.hpp. I
haven't kept up with the recent operators.hpp hacking, so I'll have to wait
for a working version before I can do much more.
Attached are the resulting rational.hpp and rational_example.cpp. These
should now be the up to date versions.
Paul.
[Non-text portions of this message have been removed]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk