|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 傾小靈 于 2021-6-30 15:43 编辑 #include<iostream>
using namespace std;
class Time
{
public: Time(int h,int m,int s)
{
hours = h;
minutes = m;
seconds = s;
}
void display()
{
cout<<"出生时间: "<<hours<<"时"<<minutes<<"分"<<seconds<<"秒"<<endl;
}
protected:
int hours,minutes,seconds;
};
class Date
{
public:
Date(int m,int d,int y)
{
month = m;
day = d;
year = y;
}
void display()
{
cout<<"出生年月: "<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
}
protected:
int month,day,year;
};
class Birthtime: public Time, public Date
{
public:
string childname;
Birthtime(string childname, int year, int month, int day, int hours, int minutes, int seconds);
void display()
{
cout << childname<<endl;
Date::display();
Time::display();
}
};
int main()
{
Birthtime N[] = { Birthtime("张三", 2002, 1, 8, 6, 6, 6),Birthtime("李四", 2002, 5, 28, 8, 8, 58),Birthtime("王五", 2002, 12, 7, 8, 9, 11) };
for (int i = 0; i < 3; i++)
{
cout << "孩子的详细信息为 名字 ";
N[i].display();
}
return 0;
}
目的是用类表示孩子的生日日期和姓名
编译器显示[Error] ld returned 1 exit status
要怎么改?
救救孩子吧!
Birthtime(string childname, int year, int month, int day, int hours, int minutes, int seconds); //这里构造函数没有定义
改为 Birthtime(string childname, int year, int month, int day, int hours, int minutes, int seconds) :
Time(hours, minutes, seconds), Date(month, day, year), childname(childname) {}
|
|