friend operators
Bernd Speiser
bernd.speiser@uni-tuebingen.de
Thu Aug 15 10:06:00 GMT 2002
Hi,
I´m still using gcc 2.95.3 on a SuSE Linux 7.3 system.
I´m trying to write some C++ code which uses operator overloading in a
friend situation. Also this is within a template (but I have already
observed all requirements pointed to in the FAQ, so this is ok, and the
problem also appears in non-template classes).
When I have a declaration like
friend ostream & operator<< (ostream &, VariableQuantity<U, D> &);
and I declare later another operator<< with different argument types,
e.g.
void operator<< (string &);
this does not work if the second operator<< is NOT a friend.
Then I get the error message
../Quantity/Quantity.h: In instantiation of `Quantities::VariableQuantity<Units:
:QuantityUnit<Quantities::LengthUnitClass>,Dimensions::QuantityDimension<Quantit
ies::LengthDimensionClass> >':
Length.h:431: instantiated from here
../Quantity/Quantity.h:852: invalid use of undefined type `class Quantities::Var
iableQuantity<Units::QuantityUnit<Quantities::LengthUnitClass>,Dimensions::Quant
ityDimension<Quantities::LengthDimensionClass> >'
../Quantity/Quantity.h:907: forward declaration of `class Quantities::VariableQu
antity<Units::QuantityUnit<Quantities::LengthUnitClass>,Dimensions::QuantityDime
nsion<Quantities::LengthDimensionClass> >'
../Quantity/Quantity.h:852: confused by earlier errors, bailing out
when I try to instantiate the template (or, if this is not a template class, if
I just want to use the class).
If the second operator<< is also a friend, it compiles ok.
Is there something illegal about my code?
Thanks for any help.
Bernd
--
=======================================================================
Bernd Speiser
Institut f"ur Organische Chemie
Auf der Morgenstelle 18
D-72076 T"ubingen
Germany
phone: +49-7071-2976205 (office) +49-7071-2976242 (laboratory)
fax: +49-7071-295518 (new!)
e-mail: bernd.speiser@uni-tuebingen.de
Internet: http://www.uni-tuebingen.de/speiser
=======================================================================
More information about the Gcc-help
mailing list