Neal Becker schrieb:
>> No. Array references (x[i]) and attribute references (x.a) represent
>> "locations". Function calls represent values. This is no different
>> than the distinction between lvalues and rvalues in C.
>>
> 
> Except this syntax is valid in c++ where X() is a constructor call:
> 
> X(whatever) += 2; is (or can be) valid c++

That's actually the less-interesting case. You would have to overload
+= to make it work, right?

The more interesting case is when X is a function that returns a
reference:

int& X(int);

void foo(){
  X(1) += 2;
}

int bar, foobar;
int& X(int t){
  if(t)  return bar;
  return foobar;
}

Here, which variable gets incremented depends on whether the t
argument is true; no overloading of assignment comes into play.

The trick is that C++ has functions that *return* lvalues;
neither C nor Python has such things.

Regards,
Martin
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to