What is const_cast - C++ Data Type

C++ examples for Data Type:Cast

Introduction

If you want to convert from a const to a non const or from a volatile to a non volatile, you use const_cast.

Demo Code

int main() {/*from w w w.  j  a v a 2  s .co m*/
   const int i = 0;
   int* j = (int*)&i; // Deprecated form
   j  = const_cast<int*>(&i); // Preferred
   volatile int k = 0;
   int* u = const_cast<int*>(&k);
}

Related Tutorials