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();
}
完整报错为
error C2504: 'employee' : base class undefined
fatal error C1004: unexpected end of file found 展开
#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();
}
完整报错为
error C2504: 'employee' : base class undefined
fatal error C1004: unexpected end of file found 展开
3个回答
展开全部
#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:
static int year;
static int month;
static int day;
public:
Date() {}
static void SetYear(int _year)
{
year= _year;
}
static void SetMonth(int _month)
{
month = _month;
}
static void SetDay(int _day)
{
day = _day;
}
static int GetYear()
{
return year;
}
static int GetMonth()
{
return month;
}
static 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(char* number="0",char* name="jiangwei",char* sexity="male",char* position="employee",int year=1994,int month=7,int day=28,double wage=0)
{
//number = new char[x]; ;
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);
}
};
int employee::Date::year = 0;
int employee::Date::month = 0;
int employee::Date::day = 0;
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)
{
this->worktime=worktime;
}
void display()
{
wage=25*worktime;
cout<<"wage:"<<wage<<endl;
}
};
void main()
{
technician p1("123456","weng","male","director",8,1994,7,28);
p1.display();
}
仅供参考,继续交流!
展开全部
#include<iostream>
using namespace std;
#include<string.h>
class Date
{
private:
static int year;
static int month;
static int day;
public:
static void SetYear(int _year)
{
year=_year;
}
static void SetMonth(int _month)
{
month=_month;
}
static void SetDay(int _day)
{
day=_day;
}
static int GetYear()
{
return year;
}
static int GetMonth()
{
return month;
}
static int GetDay()
{
return day;
}
};
int Date::year = 0;
int Date::month = 0;
int Date::day = 0;
class employee
{
protected:
char number[50];
char name[30];
char sexity[10];
char position[30];
double wage;
public:
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::GetYear(),Date::GetMonth(),Date::GetDay())
{
this->worktime=worktime;
}
void display()
{
wage=25*worktime;
cout<<"wage:"<<wage<<endl;
}
};
void main()
{
technician p1("123456","weng","male","director",8,1994,7,28);
p1.display();
}
----------------------------------------
只能说类设计得一塌糊涂,虽然我也好不了多少(1年前)。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
类雇员没有看到吗?
你这样做类? ?
你这样做类? ?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询