I trying to udnerstand const reference. In the code below does it mean that what is being returned by get() is not the copy of x (a copy of x like in pass by value) but a reference to x, which is a const, so it can not be changed?
1 2 3 4 5 6
class MyClass {
public:
int x;
MyClass(int val) : x(val) {}
constint& get() {return x;}
};
Copy elision is never applied on members (unless a clever optimiser exploits the as-if rule).
Move from a member is possible if we explicitly write code to support move semantics.