我正在学习动态记忆,但事情并不顺利.我有一个函数接受一个数字作为输入,并应该生成一个这样大小的数组.
class Doctor {
public:
Doctor();
void fillOut();
void listPatients();
void patientReset();
~Doctor();
private:
string name;
int numPatients;
string *patientList;
};
Doctor::Doctor() {
name = "";
numPatients = 0;
patientList = new string[numPatients];
}
Run Code Online (Sandbox Code Playgroud)
(第3代码块中最相关的代码).
void Doctor::fillOut()
{
string buffer = "";
string buffer2 = "";
size_t found;
bool valid = false;
int numP = 0;
int tester = 0;
bool validNum = false;
while(!valid)
{
cout << "Enter doctor name: ";
getline(cin, buffer);
found = buffer.find_first_of("1234567890!@#$%^&*()-=_+/<>?;':][");
if(string::npos == found) …Run Code Online (Sandbox Code Playgroud)