As per book The C++ Programming Language, 4th Edition -
In C and in older C++ code, you could assign a string literal to a non-const char∗:
void f() { char∗ p = "Plato"; // error, but accepted in pre-C++11-standard code p[4] = 'e'; // error : assignment to const }
It would obviously be unsafe to accept that assignment. It was (and is) a source of subtle errors, so please don’t grumble too much if some old code fails to compile for this reason.
It suggest that, above code should give error, but I am getting a warning instead.
warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
Aucun commentaire:
Enregistrer un commentaire