基本上我正在尝试多态性.我有2个对象,一个客户和一个员工.客户有姓名和投诉.员工有姓名和薪水.
在循环中,我接受这些参数并创建一个新的Person来添加到数组中.
但这是我的问题:如果我在字符串中放置任何空格,那么循环就会结束.
Person *persons[10];
for (int i = 0; i < sizeof persons;i++)
{
cout<<"Please type 1 for customer or 2 for Employee"<<endl;
int q;
cin>>q;
string name;
int salary;
string complaint;
if (q == 1)
{
cout<<"What is your name?"<<endl;
cin>>name;
cout<<"What is your complaint"<<endl;
cin>>complaint;
personPtr = new Customer(name,complaint);
cout<<"Created customer"<<endl<<endl;
persons[i] = personPtr;
cout<< "added to array"<<endl<<endl;
}
else if(q==2)
{
cout<<"What is your name?"<<endl;
cin>>name;
cout<<"What is your salary"<<endl;
cin>>salary;
personPtr = new Employee(name,salary);
persons[i] …Run Code Online (Sandbox Code Playgroud)