目前,Im试图为学生设立成员职能,该成员的职能是用药进行扼杀,作为这一职能的理由,然后用数据制造学生的物体。 然而,这是否给我留下了错误。 我知道这一职能正在缩小,但在新目标产生之后,它就留下了这一错误。
错误:
./a.out
Please insert name for student:
Bob_Russel
terminate called after throwing an instance of std::bad_alloc
what(): std::bad_alloc
Aborted
Constructor:
Student::Student(string tname){
name = tname;
}
职能:
Student Student::readStudent(istream &i){
Student *stud;
string y;
i >> y;
stud = new Student(y);
return *stud;
}
测试
#include "Student.h"
int main(){
Student *stud3;
cout << "
Please insert name for student:
";
stud3->readStudent(cin);
return 0;
}