我是C++的新手,我有一个医生的载体.
我用以下代码添加了一位新医生:
void DoctorAdmin::setDoctor(std::string lastname, std::string forename,
Person::Sex sex){
//Create new doctor
Doctor* doc = new Doctor(lastname, forename, sex);
//insert at the end of the vector
doctors.push_back(doc);
}
Run Code Online (Sandbox Code Playgroud)
然后我想在控制台上显示他们的信息:
void DoctorAdmin::showDoctors(){
cout << "Doctors:" << endl;
cout << "Name" << "\t\t\t" << "Forename" << "\t\t\t" << "Sex" << endl;
for (vector<Doctor*>::iterator i = doctors.begin(); i != doctors.end(); i++){
Doctors* doc = doctors.at(i);
cout << doc->getName() << "\t\t\t" << doc->getForename() << "\t\t\t"
<< doc->getSex() << endl;
}
Run Code Online (Sandbox Code Playgroud)
这样做后,我得到两个错误:
E0304 No instance …Run Code Online (Sandbox Code Playgroud)