このコードを見てください: コンソールから多数の文字列を読み込んで、それらを動的配列に格納しようとしています。
int Doctor::addPatients()
{
string* names = NULL;
int num;
cout << "how many patients are to be added? ";
cin >> num;
numPatients=num;
names = new string[numPatients];
for(int i=0;i++;i<numPatients){
cout << "enter the next patient's name: ";
cin.clear();
cin >> names[i];
}
patients = names; //patients is a private member variable of class Doctor
}
このコードを実行すると、次のエラーが発生します。
malloc: *** error for object 0x10c100898: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
どんな助けでも大歓迎です