【发布时间】:2015-08-22 14:23:50
【问题描述】:
我在尝试从 2 个结构中检索信息时遇到问题。 第一个是:
struct PhoneCall{
std::string date;
int minutes;
int seconds;
第二个是:
struct Bill{
Customer holder;
Plan plan;
PhoneCall callList[BILL_CALL_LIST_SIZE];
int count;
long durationSeconds;
int block;
我已经突出显示了从 struct PhoneCall 创建的 PhoneCall。
我需要解决函数
int GetTotalHours(Bill&bill)
我发现很难创建从 bill 到 Phonecall 的指针。我收到一条消息说不存在转换。
此后,我尝试了以下代码作为解决方案。(我使用过类似的东西,但它似乎返回地址 001A11EF)。
int total_hours = 0;
for (int call = 0; call < BILL_CALL_LIST_SIZE; ++call)
{
total_hours += bill.callList[call].minutes / 60+ bill.callList[call].seconds / 3600;
}
return total_hours;
稍后还有另一个函数返回总分钟数,这就是为什么 GetTotalHours 函数是 int 类型的原因。
我对编程非常陌生,并且已经跳入深渊,但希望您能提供帮助:)
【问题讨论】:
-
我知道你的两个结构是如何相互关联的,但我仍然不知道你想要做什么或者你所说的“指向两种不同类型的指针”是什么意思
-
不确定你在问什么。请澄清。
-
不清楚你在问什么
-
嗨@Giorgi 我已经编辑了我的问题,希望它能让你更清楚地理解我的问题。
-
@muppetblues 你不应该使用
int你应该使用double作为total_hours,否则你会看到integer division
标签: c++ arrays pointers struct