标题:c++编程使用派生类出现如下错误怎么回事啊
只看楼主
winner1995
Rank: 2
等 级:论坛游民
帖 子:64
专家分:41
注 册:2015-10-11
结帖率:88.89%
已结贴  问题点数:20 回复次数:3 
c++编程使用派生类出现如下错误怎么回事啊
#include<iostream>
#include<string>
using namespace std;
class student
{private:
int num;
string name;
char sex;
public:
void get_value()
{cout<<"num,name,sex:"<<"\t";
cin>>num>>name>>sex;}
void display()
{cout<<"num"<<"\t"<<"name"<<"\t"<<"sex"<<endl;
cout<<num<<"\t"<<name<<"\t"<<sex<<ednl;

};
class student1:public student
{
private:
    int age;
    string addr;
public:
void get_value_1()
{cout<<"enter age,addr:"<<endl;
cin>>age>>addr;}
void display_1()
{cout<<"num:"<<"\t"<<"name"<<"\t"<<"sex"<<"\t"<<"age"<<"\t"<<"address"<<endl;
cout<<num<<"\t"<<name<<"\t"<<sex<<"\t"<<age<<"\t"<<addr<<endl;
}

};
int main()
{student1 stud;
stud.get_value();
stud.get_value_1();
stud.display();
stud.display_1();
return 0;
}


错误如下:
Compiling...
c++xiti2.cpp
C:\编程\Visual+C+++6.0(支持win7)\Microsoft Visual Studio\Common\MSDev98\Bin\c++xiti2.cpp(19) : error C2504: 'student' : base class undefined
C:\编程\Visual+C+++6.0(支持win7)\Microsoft Visual Studio\Common\MSDev98\Bin\c++xiti2.cpp(41) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
搜索更多相关主题的帖子: private display include public 
2015-11-12 09:03
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:14 
排版一下,自己就能发现问题了
2015-11-12 09:08
winner1995
Rank: 2
等 级:论坛游民
帖 子:64
专家分:41
注 册:2015-10-11
得分:0 
?不懂

唯望君安~
2015-11-12 09:23
winner1995
Rank: 2
等 级:论坛游民
帖 子:64
专家分:41
注 册:2015-10-11
得分:0 
ok了  
#include<iostream>
#include<string>
using namespace std;
class student
{private:
int num;
string name;
char sex;
public:
void get_value()
{cout<<"num,name,sex:"<<"\t";
cin>>num>>name>>sex;}
void display()
{cout<<"num"<<"\t"<<"name"<<"\t"<<"sex"<<endl;
cout<<num<<"\t"<<name<<"\t"<<sex<<endl;}
};
class student1:public student
{
private:
    int age;
    string addr;
public:
void get_value_1()
{cout<<"enter age,addr:"<<endl;
cin>>age>>addr;}
void display_1()
{cout<<"age"<<"\t"<<"address"<<endl;
cout<<"\t"<<age<<"\t"<<addr<<endl;
}

};
int main()
{student1 stud;
stud.get_value();
stud.get_value_1();
stud.display();
stud.display_1();
return 0;
}

唯望君安~
2015-11-12 09:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-459116-1-1.html




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

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