curly-brace-aphobic?

Rainer Deyke root at rainerdeyke.com
Tue Jan 30 11:29:26 EST 2001


"Quinn Dunkan" <quinn at groat.ugcs.caltech.edu> wrote in message
news:slrn97cu0u.eti.quinn at groat.ugcs.caltech.edu...
> If C++ allows 'f(x) = y;', then C++ is truly weird.  What is *that*
supposed
> to mean?  'f(x)' returns a value, and assigning to a value makes no sense.
> You assign to variables, not values.  I could understand '*(f(x)) = y;',
but
> the only way I can see to get 'f(x) = y;' to do what you want is to have
'f'
> return an lvalue.  Icon does stuff like that, but it has an excuse: it's
icon.
> Just out of curiosity, what is the type of the C++ 'f' function above (and
> don't say "cpp macro" :) ?  It's likely C++'s idea of assignment is one
I'm
> not familiar with.

'f' here is a function that returns a reference:

int& f(int);

This is particularily useful when implementing 'operator[]':

struct array {
  int data[5];
  int& operator[](int n) { return data[n]; }
};

array a;
a[0] = 5;
a.operator[](0) = 5; // This statement is equivalent to the one above it.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list