Hi, Kurt Kuzba!
On 24 Sep 97 03:19:52 you wrote to Jamie Kowinsky
KK> friend ostream &operator<<(ostream&, const MathCalc&);
KK> // This function is an ostream friend and has access to
KK> // ostream functions. It returns an ostream object which
KK> // is created within the friend function
KK> ostream &operator<<(ostream &O, const MathCalc &MC)
KK> {
KK> // This function creates an ostream object. It accepts an
KK> // ostream object and a data object. It then formats the
KK> // data in the data object to an ostream format and returns
KK> // the ostream to the calling function.
KK> O << MC.iVar1 << " " << MC.cOperation << " " << MC.iVar2
KK> << " = " << MC.iResult << "\n\r" << flush;
KK> return O;
KK> }
The functions are correct but the comments aren't. The function does _not_
create a stream. (Nor it has to). It accepts a stream (by ref) as param and
returnd that same stream.
When you put:
cout << myMC;
the compiler invoke
operator << ( typeof(cout), typeof(myMC));
The same stream must be returned to take advantage of chaining, like
cout << myMC << " " << 1 << "\n";
that will output myMC to cout, then " " to the stream returned by the
previous function (cout too), then the same happens to all other elements.
Paul
... Anybody got a magnet?
--- OS/2 Warp
---------------
* Origin: The FlintStones' Cave in BedRock (2:371/20)
|