| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 633 人关注过本帖
标题:c++程序查错
只看楼主 加入收藏
ronaldowsy
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2008-10-20
收藏
 问题点数:0 回复次数:2 
c++程序查错
麻烦大家给我看一下,我真的找不出错误的原因了,我的编译器提示的错误是不能访问私有数据!
可我并没有定义私有啊!请高手帮忙看看,谢谢
#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
    Person(string nam , char s , int a)
    {
        name=nam;
        sex=s;
        age=a;
    }
protected:
    string name;
    char sex;
    int age;
};

class Teacher :virtual public Person
{
public:
    Teacher(string nam , char s , int a , string t):Person(nam , s ,a)
    {
        title=t;
    }
protected:
    string title;
};

class Student :virtual public Person
{
    Student(string nam , char s , int a ,float sco):Person(nam , s, a)
    {
        score=sco;
    }
protected:
    float score;
};

class Graduate :public Teacher ,public Student
{
public:
    Graduate(string nam , char s , int a , string t , float sco , float w)
        :Person(nam , s ,a),Teacher(nam , s , a , t),Student(nam , s , a ,sco),wage(w)
    {
        
    }
    void show()
    {
        cout<<"name:"<<name<<endl;
        cout<<"age:"<<age<<endl;
        cout<<"sex:"<<sex<<endl;
        cout<<"score:"<<score<<endl;
        cout<<"title:"<<title<<endl;
        cout<<"wages:"<<wage<<endl;
    }
protected:
    float wage;
};

int main()
{
    Graduate grad("WangSiyang",'B',23,"assistant",90,500000);
    grad.show();
    return 0;
}
搜索更多相关主题的帖子: include public 编译器 title 
2008-11-12 22:45
newyj
Rank: 2
等 级:新手上路
威 望:3
帖 子:542
专家分:0
注 册:2008-1-4
收藏
得分:0 
程序代码:
#include<iostream>
#include<string>
using namespace std;
class Person
{
public:
    Person(string nam , char s , int a)
    {
        name=nam;
        sex=s;
        age=a;
    }
protected:
    string name;
    char sex;
    int age;
};

class Teacher :virtual public Person
{
public:
    Teacher(string nam , char s , int a , string t):Person(nam , s ,a)
    {
        title=t;
    }
protected:
    string title;
};

class Student :virtual public Person
{
  public:                                                           //缺少public
    Student(string nam , char s , int a ,float sco):Person(nam , s, a)
    {
        score=sco;
    }
protected:
    float score;
};

class Graduate :public Teacher ,public Student
{
public:
    Graduate(string nam , char s , int a , string t , float sco , float w)
        :Person(nam , s ,a),Teacher(nam , s , a , t),Student(nam , s , a ,sco),wage(w)
    {
        
    }
    void show()
    {
        cout<<"name:"<<name<<endl;
        cout<<"age:"<<age<<endl;
        cout<<"sex:"<<sex<<endl;
        cout<<"score:"<<score<<endl;
        cout<<"title:"<<title<<endl;
        cout<<"wages:"<<wage<<endl;
    }
protected:
    float wage;
};

int main()
{
    Graduate grad("WangSiyang",'B',23,"assistant",90,500000);
    grad.show();
    return 0;
}
2008-11-12 23:23
ronaldowsy
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2008-10-20
收藏
得分:0 
非常感谢,真的很感谢
2008-11-12 23:31
快速回复:c++程序查错
数据加载中...
 
   



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

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