【发布时间】:2018-09-08 03:19:28
【问题描述】:
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);
Student 是 Person 的子结构,最后 5 行显示错误 no instance of constructor Student::Student 与参数列表匹配,我想不出问题。 这是构造函数:
Student::Student(char * na, int nm) {
this->name = na;
this->number = nm;
}
如果有人能帮忙解释一下,我将不胜感激。
【问题讨论】:
-
关于指向字符数组的字符串指针的警告:如果您错误地存储了自动(AKA 本地)变量,则很容易拥有dangling pointer。一旦 Automatic ariable 到达其范围的尽头,它就不再安全访问。更糟糕的是,这通常不会立即产生明显的错误,让您摸不着头脑,稍后在错误的位置寻找错误。
标签: c++ constructor compiler-errors