Outputing an "auto" variable (#31263)
This commit is contained in:
committed by
Quincy Larson
parent
94b2b1cd8f
commit
a1ff408e00
@ -28,6 +28,10 @@ std::pair<std::string, unsigned int>> last_employee = employees.back();
|
|||||||
|
|
||||||
// with auto, you just have to write:
|
// with auto, you just have to write:
|
||||||
auto last_employee = employees.back();
|
auto last_employee = employees.back();
|
||||||
|
//if you want to output the "last_employee" variable you have to do it with a pointer
|
||||||
|
cout<<last_employee; //you will get an error to this
|
||||||
|
cout<<*last_employee; // this will run correctly
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Once the compiler determines the type on the right side of the `=` it replaces `auto` with that type.
|
Once the compiler determines the type on the right side of the `=` it replaces `auto` with that type.
|
||||||
|
Reference in New Issue
Block a user