c++中类中类的继承与派生问题,报错为 error C2504: 'employee' : base class undefined
程序为#include<iostream>usingnamespacestd;#include<string.h>classemployee{protected:char...
程序为
#include<iostream>
using namespace std;
#include<string.h>
class employee
{
protected:
char number[50];
char name[30];
char sexity[10];
char position[30];
double wage;
class Date
{
private:
int year;
int month;
int day;
public:
void SetYear(int year)
{
this->year=year;
}
void SetMonth(int month)
{
this->month=month;
}
void SetDay(int day)
{
this->day=day;
}
int GetYear()
{
return year;
}
int GetMonth()
{
return month;
}
int GetDay()
{
return day;
}
};
public:
employee(char* number,char* name,char* sexity,char* position,int year,int month,int day)
{
strcpy(this->number,number);
strcpy(this->name,name);
strcpy(this->sexity,sexity);
strcpy(this->position,position);
Date::SetYear(year);
Date::SetMonth(month);
Date::SetDay(day);
}
employee()
{
number=0;
name=jiangwei;
sexity=male;
position=employee;
wage=1500;
Date::year=1994;
Date::month=7;
Date::day=28;
}
employee(char* number=0,char* name="jiangwei",char* sexity="male",char* position="employee",int year=1994,int month=7,int day=28,double wage=0)
{
strcpy(this->number,number);
strcpy(this->name,name);
strcpy(this->sexity,sexity);
strcpy(this->position,position);
Date::SetYear(year);
Date::SetMonth(month);
Date::SetDay(day);
};
class technician : public employee
{
protected:
double worktime;
public:
technician(char* number,char* name,char* sexity,char* position,double worktime,int year,int month,int day) : employee(number,name,sexity,position,Date::year,Date::month,Date::day)
{
this->worktime=worktime;
}
void display()
{
wage=25*worktime;
cout<<"wage:"<<wage<<endl;
}
};
void main()
{
technian p1("123456","weng","male","director",8,1994,7,28);
p1.show();
} 展开
#include<iostream>
using namespace std;
#include<string.h>
class employee
{
protected:
char number[50];
char name[30];
char sexity[10];
char position[30];
double wage;
class Date
{
private:
int year;
int month;
int day;
public:
void SetYear(int year)
{
this->year=year;
}
void SetMonth(int month)
{
this->month=month;
}
void SetDay(int day)
{
this->day=day;
}
int GetYear()
{
return year;
}
int GetMonth()
{
return month;
}
int GetDay()
{
return day;
}
};
public:
employee(char* number,char* name,char* sexity,char* position,int year,int month,int day)
{
strcpy(this->number,number);
strcpy(this->name,name);
strcpy(this->sexity,sexity);
strcpy(this->position,position);
Date::SetYear(year);
Date::SetMonth(month);
Date::SetDay(day);
}
employee()
{
number=0;
name=jiangwei;
sexity=male;
position=employee;
wage=1500;
Date::year=1994;
Date::month=7;
Date::day=28;
}
employee(char* number=0,char* name="jiangwei",char* sexity="male",char* position="employee",int year=1994,int month=7,int day=28,double wage=0)
{
strcpy(this->number,number);
strcpy(this->name,name);
strcpy(this->sexity,sexity);
strcpy(this->position,position);
Date::SetYear(year);
Date::SetMonth(month);
Date::SetDay(day);
};
class technician : public employee
{
protected:
double worktime;
public:
technician(char* number,char* name,char* sexity,char* position,double worktime,int year,int month,int day) : employee(number,name,sexity,position,Date::year,Date::month,Date::day)
{
this->worktime=worktime;
}
void display()
{
wage=25*worktime;
cout<<"wage:"<<wage<<endl;
}
};
void main()
{
technian p1("123456","weng","male","director",8,1994,7,28);
p1.show();
} 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
没有见到
class employee?
你的这个类呢??
class employee?
你的这个类呢??
更多追问追答
追问
第一个不就是么?
追答
oh 看到了,原来你在一个类的内部又写了一个类。
employee(char* number=0,char* name="jiangwei",char* sexity="male",char* position="employee",int year=1994,int month=7,int day=28,double wage=0)
{
strcpy(this->number,number);
strcpy(this->name,name);
strcpy(this->sexity,sexity);
strcpy(this->position,position);
Date::SetYear(year);
Date::SetMonth(month);
Date::SetDay(day);
}; //这里是否缺少一个 } 上面的employee这个构造函数结束的}呢?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询