Quote Originally Posted by sszd
Anyway, my curiosity has still got the better of me. I would like to see a valid assignment for the following declaration without casting constness away...
Code:
const char** cpp = ???;
Not sure quite what you want here, but do you mean this:
Code:
const char* cp = "foo";
const char**cpp = &cp;
Quote Originally Posted by sszd
Also, I tried the following and am confused...
Code:
const char c = 'A';
char* p;
const char** cpp = static_cast<const char* const*> (&p);  // Why is this allowed???
*cpp = &c;  // Because now you can do this
*p = 'B';	 // and this.
I would think the assignment to cpp would generate a compiler error. Note that no constness has been removed, only added (we have cast to a non-const pointer to a const pointer to a const char). But then it looks as if the inside const pointer is implicitly removed since the declaration is for non-const pointers. Could this possibly be a compiler bug???
Yes, the code should not compile - the assignment of the return of the static_cast to cpp is not valid, since it is removing a const. What's your compiler?