| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 312 人关注过本帖
标题:公用继承纠错
只看楼主 加入收藏
zhy0401052
Rank: 1
等 级:新手上路
帖 子:27
专家分:2
注 册:2009-7-19
结帖率:87.5%
收藏
已结贴  问题点数:20 回复次数:3 
公用继承纠错
#include<iostream.h>
#include<string.h>

class student
{public:
void get_value()
{cin>>num>>name>>sex;}
void display()
{cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
private:
    int num;
    string name;
    char sex;
};
class student1:public student
{public:
void display_1()
{
cout<<"age:"<<age<<endl;
cout<<"address:"<<address<<endl;
private:
    int age;
    string address;
};
int main()
{student std1;
std1.get_value();
std1.display();
student1 std2(18,"henan");
std2.display_1();
return 0;
}
哪位兄弟帮忙看下,出了什么问题?谢谢了!
搜索更多相关主题的帖子: 公用继承 
2009-08-13 15:08
zhy0401052
Rank: 1
等 级:新手上路
帖 子:27
专家分:2
注 册:2009-7-19
收藏
得分:0 
调试时显示
--------------------Configuration: gongyoujicheng - Win32 Debug--------------------
Compiling...
gongyoujicheng.cpp
c:\documents and settings\administrator\桌面\ggg\gongyoujicheng.cpp(19) : error C2504: 'student' : base class undefined
c:\documents and settings\administrator\桌面\ggg\gongyoujicheng.cpp(32) : error C2018: unknown character '0xa3'
c:\documents and settings\administrator\桌面\ggg\gongyoujicheng.cpp(32) : error C2018: unknown character '0xbb'
c:\documents and settings\administrator\桌面\ggg\gongyoujicheng.cpp(36) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
 
gongyoujicheng.obj - 4 error(s), 0 warning(s)
2009-08-13 15:09
xufen340
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:166
专家分:1351
注 册:2009-8-7
收藏
得分:20 
你写的代码格式要改正改正,里面问题看起来也方便点,还算好简单。
#include<iostream>
#include<string>
using namespace std;
class student
{
public:
    void get_value() {cin>>num>>name>>sex;}
    void display() {
         cout<<"num:"<<num<<endl;
         cout<<"name:"<<name<<endl;
         cout<<"sex:"<<sex<<endl;
    }
private:
    int num;
    string name;
    char sex;
};
class student1:public student
{
public:
    student1(int age1,string address1):age(age1),address(address1){}
    void display_1() {
        cout<<"age:"<<age<<endl;
        cout<<"address:"<<address<<endl;
    }
private:
    int age;
    string address;
};
int main()
{
   student std1;
   std1.get_value();
   std1.display();
   student1 std2(18,"henan");
   std2.display_1();
   return 0;
}
2009-08-13 16:21
zhy0401052
Rank: 1
等 级:新手上路
帖 子:27
专家分:2
注 册:2009-7-19
收藏
得分:0 
谢谢兄弟指教!
2009-08-13 16:23
快速回复:公用继承纠错
数据加载中...
 
   



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

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