const_cast Demo : const cast « Development « C++






const_cast Demo

const_cast Demo
#include <iostream>
using namespace std;

void f(const double &i)
{
  double &v = const_cast<double &> (i);

  v = 100.0;
}


int main()
{
  double x = 98.6;

  cout << x << endl;
  f(x);
  cout << x << endl;

  return 0;
}



           
       








Related examples in the same category

1.Demonstrates const_castDemonstrates const_cast
2.Demonstrate const_cast.Demonstrate const_cast.
3.Use const_cast on a const reference.Use const_cast on a const reference.