Chapitre précédent | Sommaire principal | Chapitre suivant |
---|
#include <iostream> #include <string> int x = 3; const int& GetX() { return x; } void DoStuff() { x = 5; } int main() { const auto& myConstX = GetX(); std::cout << "x: " << myConstX << "\n"; // prints 3 DoStuff(); std::cout << "x: " << myConstX << "\n"; // prints 5 }
#include <iostream> #include <string> void what_happens(int & i, int const& j) { i += 5; if(i == j) std::cout << "Giggity.\n"; } int main() { int val = 17; what_happens(val, val); return 0; }
https://isocpp.org/wiki/faq/const-correctness
Chapitre précédent | Sommaire principal | Chapitre suivant |
---|