String literals are pointers to arrays of constant characters ["char const *
"]. Because of this, in your function "Store( )
", you're attempting to copy a pointer to constant data ["value
"] to a pointer to non-constant data ["a
"]. This violates const-correctness, and is therefore not allowed.
That said, your "Store( )
" function, once instantiated (type-deduction), becomes this:
void Store(char *&var, char const *value)
var = value; // Error; cannot convert from "char *" to "char const *".
|"If I do it like this, it works:"
char* b = "Hello!";
Don't do that. Here, your giving "b
" the address of constant data, without respecting the constness of the string literal. Attempting to modify the string in any form will result in a run-time termination.