求助!想写一个年月日时分秒的类,输入然后输出,希望有大佬能帮帮忙,看一下哪错了?
#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个回答

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

datetime(); 
->
datetime() = default; 
wyxznb
想学编程的十六夜 谢谢!我知道了!
大约 2 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问