| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 507 人关注过本帖
标题:public,private
只看楼主 加入收藏
hzj199603
Rank: 2
来 自:南京
等 级:论坛游民
帖 子:18
专家分:32
注 册:2015-3-29
结帖率:33.33%
收藏
已结贴  问题点数:10 回复次数:2 
public,private
#include <iostream>
#include <string>
using namespace std;
class Teacher
{
    string name;
    int age;
    string sec;
    string address;
    int phone;
    string title;
public:
    void getna();
    void getag();
    void getse();
    void getad();
    void getph();
    void getti();
     void display();
};
class Cadre
{
    string name;
    int age;
    string sec;
    string address;
    int phone;
    string post;
public:
    void getna();
    void getag();
    void getse();
    void getad();
    void getph();
    void getpo();
    void display_1();
};
class Teacher_Cadre:public Teacher,public Cadre  //变成 class Teacher_Cadre:public Teacher,protected Cadre
{
    int wages;
public :
    void getwa();
    void show();
};
void Teacher::getna()
{
    cout <<"putin the teacher's name:";
    cin>>name;
}
void Teacher::getag()
{
    cout <<"putin the teacher's age:";
    cin>>age;
}
void Teacher::getse()
{
    cout <<"putin the teacher's sec:";
    cin>>sec;
}
void Teacher::getad()
{
    cout <<"putin the teacher's address:";
    cin>>address;
}
void Teacher::getph()
{
    cout <<"putin the teacher's phone:";
    cin>>phone;
}
void Teacher::getti()
{
    cout <<"putin the teacher's title:";
    cin>>title;
}
void Teacher::display()
{
    cout<<"name:"<<name<<"age:"<<age<<"sec:"<<sec<<"title:"<<title<<"address:"<<address<<"phone:"<<phone;
}
void Cadre::getna()
{
    cout <<"putin the teacher's name:";
    cin>>name;
}
void Cadre::getag()
{
    cout <<"putin the teacher's age:";
    cin>>age;
}
void Cadre::getse()
{
    cout <<"putin the teacher's sec:";
    cin>>sec;
}
void Cadre::getad()
{
    cout <<"putin the teacher's address:";
    cin>>address;
}
void Cadre::getph()
{
    cout <<"putin the teacher's phone:";
    cin>>phone;
}
void Cadre::getpo()/*class Teacher_Cadre:public Teacher,public Cadre变成 class Teacher_Cadre:public Teacher,protected Cadre                                                             这里为什么不让定义 */
{
    cout <<"putin the teacher's post:";
    cin>>post;
}
void Cadre::display_1()
{
    cout<<"post:"<<post;
}
void Teacher_Cadre::getwa()
{
    cout <<"putin the Teacher_Cadre'wages:";
    cin>>wages;
}
void Teacher_Cadre::show()
{
    display();
    display_1();
    cout<<"wages:"<<wages;
}
int main()
{
    Teacher_Cadre a;
    a.Teacher::getna();
    a.Teacher::getag();
    a.Teacher::getse();
    a.Teacher::getad();
    a.Teacher::getph();
    a.getpo();//class Teacher_Cadre:public Teacher,public Cadre变成 class Teacher_Cadre:public Teacher,protected Cadre之后,怎么改就对了?
    a.getti();
    a.getwa();
    a.show();
    return 0;
}
搜索更多相关主题的帖子: private address display include public 
2015-04-30 19:59
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:7 
继承的话在类定义时就可以加上,你怎么搞到函数定义里了

一片落叶掉进了回忆的流年。
2015-05-01 15:59
hzj199603
Rank: 2
来 自:南京
等 级:论坛游民
帖 子:18
专家分:32
注 册:2015-3-29
收藏
得分:0 
回复 2楼 诸葛欧阳
题上要求,类内声明,类外定义
2015-05-01 19:02
快速回复:public,private
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014741 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved