H,这是我给出错误对象的代码未声明首先使用此函数虽然一切都很好,为什么会这样?该类对 main 函数及其给出的错误不可见。
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
class time
{
int min;
int sec;
int hour;
public:
time()
{
cout << "uninitialized constructor " << endl << endl;
min = 0;
sec = 0 ;
hour = 0;
}
time(int m, int s, int h)
{
min= m;
sec = s;
hour = h;
}
void display()
{
cout << min << ":" << sec <<":" << hour ;
}
void add(time t1, time t2)
{
int sece = t1.sec+t2.sec;
int mint = t1.min + t2.min;
int hours = t1.hour + t2.hour;
time t4(sece , mint, hours);
}
};
int main(void)
{
time t1(23, 45,11);
time t2(11,59,59);
time t3;
t3.add(t1,t2);
t3.display();
getch();
}
其次,这段代码行是什么意思?
time(int h,int m,int s):hrs(h),mins(m),secs(s){}
可以用这个代替: time(int m, int s, int h) { min= m; 秒 = 秒;小时 = h; }