我是一个学生,我正在学习继承,所以我做一个简单的例子。但是,当我执行我的代码时,它只是执行了第一条语句并停止了。我怎么了我有这样的经验,要求调试。
class people
{
private:
string name;
protected:
string phone;
public:
string age;
string setName(string name)
{
this-> name = name;
}
string getName()
{
return name;
}
};
class student: public people
{
public:
string setPhone(string phone)
{
this-> phone = phone;
}
string getPhone()
{
return phone;
}
};
int main()
{
student ict;
string name, phone;
cout<<"\nEnter name: "; getline(cin,name);
ict.setName(name);
cout<<"\nEnter phone: "; getline(cin,phone);
ict.setPhone(phone);
cout<<"\nEnter age: "; cin>>ict.age;
cout<<"\n==============================\nYour info: ";
cout<<"\nName:"<<ict.getName();
cout<<"\nPhone: "<<ict.getPhone();
cout<<"\nAge: "<<ict.age;
return 0;
}