C++ deprecated conversion from string constant to 'char*'

前端 未结 11 1366
傲寒
傲寒 2020-11-22 16:01

I have a class with a private char str[256];

and for it I have an explicit constructor:

explicit myClass(const char *func)
{
    strcpy(         


        
11条回答
  •  庸人自扰
    2020-11-22 16:42

    In fact a string constant literal is neither a const char * nor a char* but a char[]. Its quite strange but written down in the c++ specifications; If you modify it the behavior is undefined because the compiler may store it in the code segment.

提交回复
热议问题