vendredi 13 décembre 2019

"xvalue has identity", why i can't cout it addreess

here figure out

  1. "has identity": address, a pointer, the user can determine whether two copies are identical.
  2. xvalue: has identity and can be moved from (e.g. the result of casting an lvalue to a rvalue reference.

here figure out

The following expressions are xvalue expressions:
3. a.m, the member of object expression, where a is an rvalue and m is a non-static data member of non-reference type;

here give an example

struct X { int n; };

X{4};                // prvalue: does not have an identity

X{4}.n;              // xvalue: does have an identity and denotes resources
                     // that can be reused

but when i try to use & to cout the address of X{4}.n, the compiler deny to compile.

cout << &X{4}.n << endl;    // error C2102:  '&' requires l-value

does this mean i can never get an xvalue's address?

Aucun commentaire:

Enregistrer un commentaire