wyxznb
想学编程的十六夜
采纳率100%
2020-05-14 12:39

求助!想写一个年月日时分秒的类,输入然后输出,希望有大佬能帮帮忙,看一下哪错了?

已采纳
#include<iostream>
using namespace std;
class time
{
private:
    int hour, minute, secend;
public:
    time();
    time(int h, int min, int s)
    {
        hour = h; minute = min; secend = s;
    }
    void settime()
    {
        cin >> hour >> minute >> secend;
    }
    int gettimeh(int h)
    {
        return hour;
    }
    int gettimem(int min)
    {
        return minute;
    }
    int gettimes(int s)
    {
        return secend;
    }
    void showtime()
    {
        cout << hour << ":" << minute << ":" << secend << " ";
    }
};
class date
{
private:
    int year, month, day;
public:
    date();
    date(int y, int m, int ri)
    {
        year = y; month = m; day = ri;
    }
    void setdate()
    {
        cin >> year >> month >> day;
    }
    int getdatey(int y)
    {
        return year;
    }
    int getdatem(int m)
    {
        return month;
    }
    int getdated(int ri)
    {
        return day;
    }
    void showdate()
    {
        cout << year << "/" << month << "/" << day << " ";
    }
};
class datetime
{
private:
    time t; date d;
public:
    datetime(); 
    datetime(int y, int m, int ri, int h, int min, int s) :d(y, m, ri), t(h, min, s){}
    datetime(datetime &dt)
    {
        t = dt.t; d = dt.d;
    }
    void setdatetime()
    {
        cout << "输入年月日时分秒" << endl;
        d.setdate(); t.settime();
    }
    void showdatetime()
    {
        cout << "输出:\n";
        d.showdate(); t.showtime();
    }

};
int main()
{
    datetime dt1;
    dt1.setdatetime();
    dt1.showdatetime();
    return 0;
}

总显示[Error] ld returned 1 exit status和未命名33.cpp:(.text+0x15): undefined reference to `datetime::datetime()',到底这么回事?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • qq_42685012 胖狗子修行之路 1年前

    默认构造函数未定义,要不就不写,用默认的,如果想显示的表达默认的
    修为为下:

    datetime(); 
    ->
    datetime() = default; 
    
    点赞 1 评论 复制链接分享