Last active
September 5, 2016 02:28
-
-
Save zironycho/48f61c29d0c887ae96a791941a644cc2 to your computer and use it in GitHub Desktop.
test auto keyword with lvalue's reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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