Warning: Invalid Conversion From  'char**'  To  'const char**

This page answers questions like these:


Related Links:
Difference Between char* and char [] and char s[n]
Difference Between char* s = "string"; and char s[] = "string";
warning/error: inline function used but never defined
error: expected primary-expression before ')' token
error: the compiler can assume that the address of '...' will always evaluate to 'true'
Static Member Function Declaration and Definition



warning/error: invalid conversion from 'char**' to 'const char**'

void func2(const char** ptr2) { ... } void func1() { char** ptr1; const char** q = ptr1; // <-- Gives a compilation warning or error! func2(ptr1); // <-- Gives a compilation warning or error! }

An Example Of Why An Implicit Cast From 'char**' To 'const char**' Is Illegal:

void func() { const TYPE c; // Define 'c' to be a constant of type 'TYPE'. TYPE* p; // Define 'p' to be a non-constant pointer to a variable of type 'TYPE'. const TYPE** cpp; // Define 'cpp' to be a non-constant pointer to a non-constant pointer to a constant of type 'TYPE'. cpp = &p; // Illegal! Assign the address of 'p' (i.e. TYPE**) to 'cpp' (i.e. const TYPE**). // This implicit cast is disallowed to prevent you writing the next line of code. *cpp = &c; // Make '*cpp' (i.e. 'p') point to 'c'. This is legal since both are of type 'const TYPE*' . // (If 'cpp' was of type 'const TYPE* const *', this assignment would be illegal.) *p = something; // Modify what 'p' points to! i.e. This would modify the constant 'c'! // This would happen without an explicit cast anywhere in the code which is clearly very dangerous! }


Related Links:
Difference Between char* and char [] and char s[n]
Difference Between char* s = "string"; and char s[] = "string";
warning/error: inline function used but never defined
error: expected primary-expression before ')' token
error: the compiler can assume that the address of '...' will always evaluate to 'true'
Static Member Function Declaration and Definition

Home  >  C++ / C  >  Warning: Invalid Conversion From  'char**'  To  'const char**


Tags: warning invalid conversion from char** to const char**, error invalid conversion from char** to const char**, invalid conversion from char** to const char**, invalid conversion, warning: invalid conversion from 'char**' to 'const char**', error: invalid conversion from 'char**' to 'const char**', warning, error, C++, C

Copyright © HelpDoco.com
code-cpp-c-warning-invalid-conversion-from-ptr-ptr-to-const-ptr-ptr.txt
C++-C/warning-invalid-conversion-from-char-pointer-pointer-to-const-char-pointer-pointer.htm
2