本文转载自:http://blog.sina.com.cn/s/blog_5e77c61f010104dt.html
C++ 代码里面:
class person
{
char name[20];
public:
setName(char* name)
{
this->name=name;
}
}
当在main函数中:setName("sujuan"),时就会出现编译错误:
warning: deprecated conversion from string constant to‘char*’
原因是编译setName函数的时候默认传来的不可修改的串,所以只需:
setName(const char* name)
{
this->name=name;
}
}