c++ cannot convert from 'int **' to 'const int **' -
this question has answer here:
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
Post a Comment