re: writing cout << "Number = " << Number << endl; without references.
JC> DJ> I'm not aware of a way to concatenate
JC> DJ> operators like this via a pointer to a class. Could you demonst
JC> No need for pointers. You can use actual objects...
So you could! I was so focused on the pointers vs references issue I
failed to look at the broader picture.
Still, the ability to return a reference to an object rather than
creating and destroying multiple objects demonstrates my point that
references are more than "syntactic sugar."
JC> DJ> I'm really curious as to why this is easy and output is
JC> DJ> straightforward. What am I missing here?
JC> You're missing the fact that the input operator has to modify its
JC> argument to do any good. If you had something like:
JC> istream istream::operator(int x) {
JC> // body
JC> }
JC> it'd be able to modify its copy of `x' on the stack, but couldn't do
JC> _anything_ to the user's original object `x'.
Meaning that the programmer would have to pass a pointer rather than the
object itself - something like:
cin << &Number;
vice
cin << Number;
Regards,
Daniel ddjones@pinn.net
---
þ RM 1.31 1604 þ Golf balls? Is that anything like tennis elbow?
---------------
* Origin: Selective Source Virginia Beach, VA (757)471-6776 (1:275/102)
|