注册 登录
编程论坛 C++教室

继承出错

不同认为 发布于 2016-05-23 21:43, 3351 次点击
#include<iostream>
using namespace std;
#include<string>
class people
{
private:
        string name;
        int age;
        string gender;
public:
        pepole(string a,int b,string c)
        {      
                name=a;
                age=b;
                gender=c;
        }
     void  disp();

};
void people::disp()
{
    cout<<"姓名:"<<name<<endl;
    cout<<"年龄:"<<age<<endl;
    cout<<"性别:"<<gender<<endl;     
}
class student:public people{
    private:
        string number;
    public:
        student(string a,int b,string c,string d):people(a,b,c)
        {
            number=d;
        }
       void  disp();        
};
void student::disp()
{
    people::disp();
    cout<<"学号:"<<number<<endl;   
}
int main()
{
    student stu("张三",14,"男","568974");
    stu.disp();
    return 0;
   
}
只有本站会员才能查看附件,请 登录
1 回复
#2
rjsp2016-05-24 08:20
pepole 改为 people

顺便说一句,你还是换书换老师吧,你这代码学下去就学废了
1