1
0

constcast.cpp 508 B

12345678910111213141516171819202122232425262728
  1. // constcast.cpp -- using const_cast<>
  2. #include <iostream>
  3. using std::cout;
  4. using std::endl;
  5. void change(const int * pt, int n);
  6. int main()
  7. {
  8. int pop1 = 38383;
  9. const int pop2 = 2000;
  10. cout << "pop1, pop2: " << pop1 << ", " << pop2 << endl;
  11. change(&pop1, -103);
  12. change(&pop2, -103);
  13. cout << "pop1, pop2: " << pop1 << ", " << pop2 << endl;
  14. // std::cin.get();
  15. return 0;
  16. }
  17. void change(const int * pt, int n)
  18. {
  19. int * pc;
  20. pc = const_cast<int *>(pt);
  21. *pc += n;
  22. }