| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 489 人关注过本帖
标题:error C2228: left of '.hour' must have class/struct/union type
收藏  订阅  推荐  打印 
cancerhd
Rank: 1
等级:新手上路
帖子:13
积分:230
注册:2007-7-25
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-8-2 11:04
medicihophy
Rank: 2
等级:注册会员
威望:1
帖子:102
积分:1120
注册:2007-7-28

以下是引用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-8-2 11:08
cancerhd
Rank: 1
等级:新手上路
帖子:13
积分:230
注册:2007-7-25
回复:(medicihophy)以下是引用cancerhd在2007-8-2 ...

Yes,that's right.Thank you very much.
2007-8-2 12:19
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.056223 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved