Skip to content

Instantly share code, notes, and snippets.

@zironycho
Last active September 5, 2016 02:28
Show Gist options
  • Save zironycho/48f61c29d0c887ae96a791941a644cc2 to your computer and use it in GitHub Desktop.
Save zironycho/48f61c29d0c887ae96a791941a644cc2 to your computer and use it in GitHub Desktop.
test auto keyword with lvalue's reference
class A {
public:
A() : _value(0) {}
int& get() { return _value; }
void print() { std::cout << _value << std::endl; }
private:
int _value;
};
int main(void) {
A a;
auto local = a.get();
local = 1;
a.print();
auto& local2 = a.get();
local2 = 2;
a.print();
return 0;
}
/*
==============================
output:
0
2
------------------------------
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment