Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 结构数组的构造函数错误,错误消息:没有与参数列表匹配的构造函数实例_C++_Constructor_Compiler Errors - Fatal编程技术网

C++ 结构数组的构造函数错误,错误消息:没有与参数列表匹配的构造函数实例

C++ 结构数组的构造函数错误,错误消息:没有与参数列表匹配的构造函数实例,c++,constructor,compiler-errors,C++,Constructor,Compiler Errors,Student是Person的子结构,最后5行显示错误:constructor Student::Student的实例与参数列表不匹配,我无法找出问题所在。 以下是构造函数: Person* studentList[5]; studentList[0] = new Student("Jane", 1); studentList[1] = new Student("Jim", 2); studentList[2] = new Student("Jacques", 3); studentList[3

Student是Person的子结构,最后5行显示错误:constructor Student::Student的实例与参数列表不匹配,我无法找出问题所在。 以下是构造函数:

Person* studentList[5];
studentList[0] = new Student("Jane", 1);
studentList[1] = new Student("Jim", 2);
studentList[2] = new Student("Jacques", 3);
studentList[3] = new Student("Juan", 4);
studentList[4] = new Student("Junlian", 5);
如果有人能解释的话,我会很感激。

C++中的字符串文字(与C不同)是<代码> const char */COD>。它们不能转换为非常量

char*
。要编译程序,您需要将构造函数签名更改为

Student::Student(char * na, int nm) {
this->name = na;
this->number = nm;
}
您还需要确保<代码>名称>代码>在<代码>学生< /代码>中声明为代码> conchch**/COD>。C++中的< /p> 字符串文字(与C不同)是“代码> const char */COD>。它们不能转换为非常量
char*
。要编译程序,您需要将构造函数签名更改为

Student::Student(char * na, int nm) {
this->name = na;
this->number = nm;
}

您还需要确保
name
Student

中声明为
const char*
一个关于字符数组字符串指针的警告:如果您错误地存储了一个自动(又称局部)变量,则很容易产生错误。Oce自动变量到达其作用域的末尾时,访问将不再安全。更糟糕的是,这通常不会立即生成一个可见的错误,这会让您挠头,稍后在错误的位置查找错误。关于字符串指针到字符数组的警告:如果您错误地存储了一个自动(也称为局部)变量,则很容易产生错误。Oce自动变量到达其作用域的末尾时,访问将不再安全。更糟糕的是,这通常不会立即生成一个可见的错误,让您挠头,稍后在错误的位置查找错误。