C++ 问题求助 error C2504: 'person' : base class undefined 未定义基类 到底是错哪了啊!
classperson//1028.h{private:intid;stringname;charsex;intage;public:person(inti,string...
class person //1028.h
{
private:
int id;string name;char sex;int age;
public:
person(int i,string n,char s,int a )
{
id=i;
name=n;
sex=s;
age=a;
}
void print()
{
cout<<"id:"<<id<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"age:"<<age<<endl;
};
class student:public person
{
private: int score;
string department;
public:
student(int i,string n,char s,int a,int sc,string d):
person(i,n,s,a)
{
score=sc;
department=d;
}
};
class teacher:public person
{
private:
string tzc;
string tbm;
public:
teacher(int i,string n,char s,int a,string zc,string bm):
person(i,n,s,a)
{
tzc=zc;
tbm=bm;
}
};
#include<iostream> //1028.CPP
#include<string>
using namespace std;
#include"1028.h"
int main()
{
person std1(20,"小明",'男',20);
std1.print();
return 0;
} 展开
{
private:
int id;string name;char sex;int age;
public:
person(int i,string n,char s,int a )
{
id=i;
name=n;
sex=s;
age=a;
}
void print()
{
cout<<"id:"<<id<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"age:"<<age<<endl;
};
class student:public person
{
private: int score;
string department;
public:
student(int i,string n,char s,int a,int sc,string d):
person(i,n,s,a)
{
score=sc;
department=d;
}
};
class teacher:public person
{
private:
string tzc;
string tbm;
public:
teacher(int i,string n,char s,int a,string zc,string bm):
person(i,n,s,a)
{
tzc=zc;
tbm=bm;
}
};
#include<iostream> //1028.CPP
#include<string>
using namespace std;
#include"1028.h"
int main()
{
person std1(20,"小明",'男',20);
std1.print();
return 0;
} 展开
展开全部
// 定义部分因为粗心丢了个大括号
class person //1028.h
{
private:
int id;string name;char sex;int age;
public:
person(int i,string n,char s,int a )
{
id=i;
name=n;
sex=s;
age=a;
}
void print()
{
cout<<"id:"<<id<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"age:"<<age<<endl;
} // 丢了个大括号
};
class person //1028.h
{
private:
int id;string name;char sex;int age;
public:
person(int i,string n,char s,int a )
{
id=i;
name=n;
sex=s;
age=a;
}
void print()
{
cout<<"id:"<<id<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"age:"<<age<<endl;
} // 丢了个大括号
};
展开全部
class person //1028.h
{
private:
int id;string name;char sex;int age;
public:
person(int i,string n,char s,int a )
{
id=i;
name=n;
sex=s;
age=a;
}
void print()
{
cout<<"id:"<<id<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"age:"<<age<<endl;
} //这里少个括号!!!
};
更多追问追答
追问
太感谢了!!!请问这是什么软件
追答
这是回答问题时的格式,百度在回答C++类问题时,可以选格式,你自己找个问题看一下回答那里就看出来了,地图旁边的那个选项
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询