c++ cannot convert from 'int **' to 'const int **' -


consider following code:

int** a; const int** b; b = a; 

this code gives error:

error c2440: '=' : cannot convert 'int **' 'const int **' conversion loses qualifiers 

why not able perform cast?

when operating simple pointers works ok.

int* a; const int* b; b = a; 

suppose able perform cast. consider:

const int n = 42; const int* cp = &n;  int* p; int** = &p;  const int** b; b = a;  // hypothetical, doesn't compile *b = cp;  // equivalent p = cp; *p = 84;  // equivalent n = 84: oops 

therefore, allowing implicit cast int** const int** allow program violate const correctness.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -