C++结构体传递参数的小问题-请指教

来源:百度知道 编辑:UC知道 时间:2024/06/03 04:10:30
定义一个时间的结构体:
struct time
{
time(){cout<<"hello\n";}
time(int m,int h){minute=m;hour=h;}
int minute;
int hour;
void set_time(int min,int h){minute=min;hour=h;}
};

然后定义一个航班结构体:
struct flight
{
int f_num;
char *start;
char *end;
time s_time;//航班出发时间
time e_time;//航班到达时间}
想在这个航班结构中设置航班的出发和到达时间下面的设置有什么问题??
该怎么设置啊??
void set_flight(int f,char* s,char* e,time &s,time &e)
{
f_num=f;
start=s;
//char *p=&start[0];
end=e;
s_time=s;
e_time=e;

}

struct time
{
time(){cout<<"hello\n";}
time(int m,int h){minute=m;hour=h;}
int minute;
int hour;
// void set_time(int min,int h){minute=min;hour=h;}
const time& operator=(const time &n) //注意这里
{
this->minute = n.minute;
this->hour = n.hour;
return *this;
}
};
struct flight
{
int f_num;
char *start;
char *end;
time s_time;//航班出发时间
time e_time;//航班到达时间
void set_flight(const int &f, char *const s, char *const e,
const time &s, const time &e)
{
f_num=f;
start=s;
//char *p=&start[0];
end=e;
s_time=s; //注意这里,你开始并没有重载"="运算符,所以这里会出错
e_time=e; //这里也是
}
};