F
fungus
Can the "auto" keyword be used to create a reference?
eg. Will this code print "2"?
int x = 1;
auto& y = x;
y = 2;
eg. Will this code print "2"?
int x = 1;
auto& y = x;
y = 2;
fungus said:Oops, typo:
Code should read:
int x = 1;
auto& y = x;
y = 2;
cout << x;
fungus said:Oops, typo:
Code should read:
int x = 1;
auto& y = x;
y = 2;
cout << x;
This seems more reliable than the "engineer's induction" I had in
mind...
Assuming that we are not required to wait for the "Oops, typo: code
should be wrapped in something that will actually compile; e.g., a main,"
followed by a "Oops, typo: code should include a header for the iostream
lib," and then the "Oops, typo: code should apply some means to resolve
`cout' to the namespace it is defined in" ...
To follow up the "yes" answers from VS2010 and gcc-4.5.0, the detail is
in [dcl.spec.auto] 7.1.6.4, where it has this example:
fungus said:I already did the "engineer's induction" ... but I've
already learned that C++ doesn't work that way.
fungus said:I was just trying to keep it ASAP...
I remember way back (well, not /that/ way) when this lesson
finally sunk in.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.