|
-
September 1st, 2006, 01:56 PM
#12
Re: const return values
Ok, after reading the link sent by TomWidmer it made a lot more sense. Although, I then went back and re-examined NMTop40's code which looks very similar and don't know why I didn't see this the first time. Like I said, I guess I'm slow.
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 = ???;
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???
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|