将结构执政传递给函数,编译出现错误
#include <iostream>using namespace std;
struct travel_time
{
int hours;
int mins;
};
const int MINS_PER_HOUR = 60;
travel_time sum(travel_time, travel_time);
void show_time(travel_time);
int main()
{
//两天旅游分别所用的时间
travel_time day1 = { 4, 54 };
travel_time day2 = { 3, 51 };
travel_time *p1 = &day1;
travel_time *p2 = &day2;
//将两天时间求和
travel_time day1_day2_total = sum(p1, p2);
travel_time *p = &day1_day2_total;
//输出总时间
show_time(p);
return 0;
}
travel_time sum(const travel_time *day1, const travel_time *day2)
{
travel_time sum;
sum.mins = (day1->mins + day2->mins) % MINS_PER_HOUR;
sum.hours = (day1->hours + day2->hours) + (day1->mins + day2->mins) / MINS_PER_HOUR;
return sum;
}
void show_time(const travel_time *total)//将结构的地址传递给函数
{
cout << "you have used " << total->hours << " hours and " << total->mins << " minutes among this trip." << endl;//使用箭头操作符
}
出现错误:错误 1 error C2664: “travel_time sum(travel_time,travel_time)”: 无法将参数 1 从“travel_time *”转换为“travel_time”
请提点一下哪里没考虑好导致出现了问题。