无法将参数 1 从“const char[4]”转换为“char * ”或者没有与参数列表匹配的构造函数实例

原来代码:

class Object {
public:
 static int count;
 char name[20];
public:
 Object( char* nam) {
  strcpy_s(name, nam);
   count++;
 }
 static void show() {
  cout << "the name is" << count << endl;
 }
};
int Object::count = 0;
void vist()
{
 Object a1("vs1");
 Object a2("vs2");
}
void main() {
 cout << "begin" << Object::count << endl;
 vist();
 Object::show();
 Object b("vs3");
 Object::show();
}

在这里插入图片描述
修改:
在:char * nam;前面加一个const
因为你输入的是一个不可修改的const型,所以也要用const来定义

发布了50 篇原创文章 · 获赞 75 · 访问量 6695

猜你喜欢

转载自blog.csdn.net/weixin_45822638/article/details/103493712