|
-
August 31st, 2006, 02:17 PM
#1
const return values
Take the following code...
Code:
const char* fn1 ()
{
return new char; }
const char** fn2 ()
{
return new char*; }
fn2() generates the following compiler error...
Error: Cannot return char** from a function that should return const char**.
...why?
It seems to me that if fn1 is valid, why not fn2? Or, if fn2 is not valid, then why should fn1 be valid? I very rarely work with pointer to pointers, but a coworker recently had a problem with this and we narrowed it down to this issue. I had no reasonable explanation but I've been able to greatly simplify and duplicate his exact problem with the above code. If someone can explain this it would be greatly appreciated. Thank you.
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
|