Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pointer to pointer to const

26 views
Skip to first unread message

Morten Frederiksen

unread,
May 25, 2005, 4:02:58 PM5/25/05
to
Can anyone explain why this does not work?

int a = 42;
int* b = &a;
const int** c = &b; // error

I get "invalid conversion from `int**' to `const int**'" from the
compiler. Logically there should not be a problem, so perhaps it is a
limitation on the compiler.

Regards
Morten Frederiksen

Max M.

unread,
May 25, 2005, 4:33:11 PM5/25/05
to
Morten Frederiksen wrote:
> int a = 42;
> int* b = &a;
> const int** c = &b; // error
>
> I get "invalid conversion from `int**' to `const int**'" from the
> compiler. Logically there should not be a problem, so perhaps it is a
> limitation on the compiler.

Logically there *is* indeed a problem. If that assignament were possibile,
you could change the content of 'b' by assigning a value to '*c'. Since
'*c' is of type 'const int*', 'b' could end up pointing to a 'const int'.

Max

Peter Julian

unread,
May 25, 2005, 7:46:23 PM5/25/05
to

"Morten Frederiksen" <nos...@nospam.nospam> wrote in message
news:4294d9f3$0$306$ba62...@nntp05.dk.telia.net...

The compiler behaves as expected.

Because the constant keyword used above implies a constant value, not a
constant pointer. Since variable a is mutable, the pointer to a constant
can't bind to it.

Note:

#include <iostream>

int main()
{
const int aa = 11;
const int bb = 22;
const int *p_a = &aa;
const int *p_b = &bb;
const int **pp_c = &p_b;
*pp_c = p_a; // ok !, mutable pointer
// **pp_c = 23; // error... const object
std::cout << "**pp_c = " << **pp_c;

return 0;
}

and...

#include <iostream>

int main()
{
int aa = 11;
int bb = 22;
int *p_a = &aa;
int *p_b = &bb;
int * const * const pp_c = &p_a;
// **pp_c = &p_a; // error... const ptr to a const ptr
// *pp_c = p_b; // error... const ptr
**pp_c = 12; // ok !, mutable object
std::cout << "**pp_c = " << **pp_c;

return 0;
}


V

unread,
Jul 14, 2023, 9:12:03 PM7/14/23
to
anglezzzzzzz.likesyou.org/a.php⠀⠀⠀⠀⠀⠀⠀ ⠀⠀
christyansworld.atwebpages.com/a.php⠀⠀⠀⠀⠀⠀⠀
youthmeetupplace.talk4fun.net/a.php⠀⠀⠀⠀⠀⠀⠀⠀
kohtumispaik3.66ghz.com/a.php⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

Heia...........Heida pilk peale nendele............


Postita ka midagi sinna.

Siis pärast hea mul lugeda, et mu lehtedel on mõni külastaja ka !

red floyd

unread,
Jul 14, 2023, 9:26:52 PM7/14/23
to
No, it's a feature of the language. Google for this error, or
https://stackoverflow.com/questions/19209882/c-cannot-convert-from-int-to-const-int

David Brown

unread,
Jul 15, 2023, 7:23:56 AM7/15/23
to
On 15/07/2023 03:26, red floyd wrote:
> On 7/14/2023 6:11 PM, V wrote:
<snip>
>>
>> Morten Frederiksen kirjutas kolmapäev, 25. mai 2005 kl 23:02:58 UTC+3:
>>> Can anyone explain why this does not work?
>>> int a = 42;
>>> int* b = &a;
>>> const int** c = &b; // error
>>> I get "invalid conversion from `int**' to `const int**'" from the
>>> compiler. Logically there should not be a problem, so perhaps it is a
>>> limitation on the compiler.
>>> Regards
>>> Morten Frederiksen
>
> No, it's a feature of the language.  Google for this error, or
> https://stackoverflow.com/questions/19209882/c-cannot-convert-from-int-to-const-int
>

Please look more carefully at what you are replying to. "V" is a
spammer and a Usenet vandal, who spends his time annoying people and
discussion forums. One of his habits is making idiotic replies to
ancient posts.

So while Morten Frederiksen was undoubtedly genuinely interested in an
answer to his original question in 2005, I do not believe he is still
waiting for the answer today.

Many people filter out posters like "V", though vandals like him
regularly change their posting nyms and addresses. By replying to his
post (especially without snipping), you are circumventing these filters
and spreading his spam to people who otherwise manage to avoid it. So
please do not do this.

red floyd

unread,
Jul 15, 2023, 7:43:59 PM7/15/23
to
On 7/15/2023 4:23 AM, David Brown wrote:
[redacgted]
> Many people filter out posters like "V", though vandals like him
> regularly change their posting nyms and addresses.  By replying to his
> post (especially without snipping), you are circumventing these filters
> and spreading his spam to people who otherwise manage to avoid it.  So
> please do not do this.
>

Thanks. Didn't realize he was a troll, had never seen him before.

Anand Hariharan

unread,
Jul 15, 2023, 10:18:52 PM7/15/23
to
0 new messages