#include<iostream>
using namespace std;
class time {
int h, m, s;
public:
time(int hh = 0, int mm = 0, int ss = 0) :h(hh), m(mm), s(ss) {}
time(int l);
friend ostream &operator<<(ostream& out, time t);
friend istream &operator>>(istream& in, time& t);
};
ostream& operator<<(ostream& out, time t) {
out << "此時的時間是" << t.h << "小時" << t.m << "分鐘" << t.s << "秒" << endl;
return out;
}
istream& operator>>(istream& in, time& t) {
cout << "輸入時間" << endl;
in >> t.h >> t.m >> t.s;
return in;
}
time::time(int l) {
h = l / 3600;
m = l % 3600 / 60;
s = l % 60;
}
int main() {
time t1(9, 3, 30), t2;
cout << t1 << t2;
operator<<(cout, t1);
cin >> t2;
cout << t2;
operator<<(cout, t2);
operator>>(cin, t2);
cout << t2;
time t3;
int s = 3600;
t3=(s);
cout << t2;
return 0;
}
uj5u.com熱心網友回復:
你的兩個建構式,因為一個帶有默認引數的原因,所以time(int)方式無法確認呼叫那一個。uj5u.com熱心網友回復:
那應該咋改啊
uj5u.com熱心網友回復:
有沒有辦法實作又能初始化又可以運行呀
uj5u.com熱心網友回復:
把你的默認引數去掉唄uj5u.com熱心網友回復:
太謝謝了感謝感謝轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/39508.html
標籤:C++ 語言
上一篇:能解釋一下第四題的每個選項嘛
