| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2317 人关注过本帖
标题: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
快速回复:error C2228: left of '.hour' must have class/struct/union type
数据加载中...
 
   



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

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