Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Created November 23, 2019 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jitpaul/a83c10df297c554b93e8fc5e702e10fb to your computer and use it in GitHub Desktop.
Save jitpaul/a83c10df297c554b93e8fc5e702e10fb to your computer and use it in GitHub Desktop.
const_cast
int a = 5;
const int* b = const_cast <const int*> (&a);
int* c = const_cast<int*> (b);
a = 10; //OK
*b = 4; //ERROR
*c = 6; //OK
int d = 5;
const int& e = const_cast<const int &> (d);
int& f = const_cast<int&>(e);
d = 10; //OK
e = 4; //ERROR
f = 6; //OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment