Dag Sverre Seljebotn skrev: > This is just wrong -- there's a fundamental difference of changing which > reference is stored in a variable in the calling scope, and modifying > objects. You can change x, but you can't reassing x. > > Perhaps my wording could have been clearer. > C++ references per definition cannot be changed, as they operate like const pointers. You can only modify the value of the variable they alias. References are logical aliases of other variables, which must be initialized to alias to an object when declared. The value of a reference can never change.
int& a; // illegal int b; int& a = b; // ok This means the same as: int *const _a = &b; #define a _a[0] So if you write int c; a = c; this change the value of b to that of c. It does not rebind a to alias c! This is a big difference between Python and C++ sematics. Assignment rebinds names in Python; assignment copies values (or whatever you overload) in C++. We have the same sematical difference when calling functions: void foobar(int& c); the reference c is intialized to alias the argument with which foobar is called. But you can never rebind c to alias another object in the local scope of foobar. If you assign to c you modify the variable aliased by c. Sturla Molden _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
