标题:error C2228: left of '.hour' must have class/struct/union type
只看楼主
cancerhd
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-7-25
 问题点数:0 回复次数:2 
error C2228: left of '.hour' must have class/struct/union type

#include<iostream>

using std::cout;
using std::endl;

struct Time
{
int hour;
int minute;
int second;
}; //½á¹¹´ø·ÖºÅ

void printMilitary(const Time &);
void printStandard(const Time &);

int main()
{
Time dinnerTime;

dinnerTime.hour = 18;
dinnerTime.second = 30;
dinnerTime.minute = 0;

cout<<"dinner will be held at: ";
printMilitary(dinnerTime);
cout<<"military time,\nwhile is: ";
(dinnerTime);
cout<<"stand time: \n";

dinnerTime.hour = 29;
dinnerTime.minute = 73;

cout<<"\n time with incalid values:";
printMilitary(dinnerTime);
cout<<endl;
return 0;
}

void printMilitary (const Time &)
{
cout<<(t.hour < 10 ?"0" :" ")<<t.hour<<":"
<<(t.minute < 10 ?"0" :" ")<<t.minute;

}

void printStandard (const Time &)
{
cout<<((t.hour = 0 || t.hour =12 ) ?
12 : t.hour & 12)
<<":"<<(t.minute < 10 ? "0" : " ")<<t.minute
<<":"<<(t.second < 10 ? "0" : " ")<<t.second
<<(t.hour < 12 ? "AM" : "PM");
}

搜索更多相关主题的帖子: hour union error left struct 
2007-08-02 11:04
medicihophy
Rank: 1
等 级:新手上路
威 望:1
帖 子:102
专家分:0
注 册:2007-7-28
得分:0 
以下是引用cancerhd在2007-8-2 11:04:50的发言:

#include<iostream>

using std::cout;
using std::endl;

struct Time
{
int hour;
int minute;
int second;
}; //½á¹¹´ø·ÖºÅ

void printMilitary(const Time &);
void printStandard(const Time &);

int main()
{
Time dinnerTime;

dinnerTime.hour = 18;
dinnerTime.second = 30;
dinnerTime.minute = 0;

cout<<"dinner will be held at: ";
printMilitary(dinnerTime);
cout<<"military time,\nwhile is: ";
(dinnerTime);
cout<<"stand time: \n";

dinnerTime.hour = 29;
dinnerTime.minute = 73;

cout<<"\n time with incalid values:";
printMilitary(dinnerTime);
cout<<endl;
return 0;
}

void printMilitary (const Time & t)where your 't'?
{
cout<<(t.hour < 10 ?"0" :" ")<<t.hour<<":"
<<(t.minute < 10 ?"0" :" ")<<t.minute;

}

void printStandard (const Time & t)where your 't'?
{
cout<<((t.hour = 0 || t.hour =12 ) ? and look at '=',should it be '=='?
12 : t.hour & 12)
<<":"<<(t.minute < 10 ? "0" : " ")<<t.minute
<<":"<<(t.second < 10 ? "0" : " ")<<t.second
<<(t.hour < 12 ? "AM" : "PM");
}

[此贴子已经被作者于2007-8-2 11:12:08编辑过]


2007-08-02 11:08
cancerhd
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-7-25
得分:0 
回复:(medicihophy)以下是引用cancerhd在2007-8-2 ...
Yes,that's right.Thank you very much.
2007-08-02 12:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-159859-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.320029 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved