2

Possible Duplicate:
Double pointer const-correctness warnings in C

Why does the cases number 1, 2 and 3 works fine in C++, but not number 4 ?

//1
char* p1;
const char* p2 = p1;

//2
char** p3;
char * const * p4 = p3;

//3
char** p5;
const char* const * p6 = p5;

//4
char** p7;
const char** p8 = p7;
Community
  • 1
  • 1
foke
  • 1,339
  • 2
  • 12
  • 20
  • 1
    See [const qualifier for pointers to pointers](http://stackoverflow.com/questions/4246445/const-qualifier-for-pointers-to-pointers) – Erik Olson Nov 14 '11 at 17:50
  • 2
    [Why am I getting an error converting a Foo** → Foo const**?](http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.17) – Praetorian Nov 14 '11 at 17:57
  • Praetorian, maybe you could post I'll accept your answer – foke Nov 14 '11 at 18:48

2 Answers2

4

See C++ FAQ - [18.17] Why am I getting an error converting a Foo** → Foo const**?

sarat
  • 10,512
  • 7
  • 43
  • 74
0

May wanted to do this instead:

//4
typedef char** PPCHAR; 
PPCHAR p7;
const PPCHAR p8 = p7;

In the original form, the compiler blames about loosing const-qualification (well yes, a pointer-to-pointer-of a constant-char is loosing const qualification when being converted to pointer-to-pointer-of a non-const-char), but if you typedef them that way you will give the precedence of interpretation the way you probably were intending initially.

F.I.V
  • 317
  • 1
  • 14