While programming with the auto keyword I sometimes liked to know the type that is used by the compiler at compile time. It does not matter if the compilation aborts where I need to know the type. Simple example:
std::vector< int > s{1, 2, 3};
for (auto elem : s) {
elem = 5;
}
for (auto elem : s) {
std::cout << elem << std::endl;
}
will print
1
2
3
because elem is of type int, not int&. It would be nice to try compile the code and get the type of elem to catch such mistakes early.
Aucun commentaire:
Enregistrer un commentaire