| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 341 人关注过本帖
标题:为什么出错。。。重载
只看楼主 加入收藏
nan1888
Rank: 2
等 级:论坛游民
帖 子:44
专家分:86
注 册:2011-6-19
结帖率:85.71%
收藏
 问题点数:0 回复次数:0 
为什么出错。。。重载
#include<iostream>
using namespace std;
class timec
{public:
int h;
int s;
int m;
void print()
{cout<<"shi"<<h<<endl;
cout<<"min"<<m<<endl;
cout<<"s"<<s<<endl}
timec(int a=0,int b=0,int c=0);
timec (int g)
 {int h=g;int s=0;int m=0;}
friend timec &operator+(const timec &c1,const timec &c2);
friend timec &operator-(const timec &c1,const timec &c2);
friend ostream &operator<<(ostream &output,const timec &c3);}
timec::timec
{a=h;
b=s;
c=m;}
timec &operator+(const timec &c1,const timec &c2)
{
a=c1.h+c2.h;
b=c1.m+c2.m;
c=c1.s+c2.s;
return timec(a,b,c);
}
time &operator-(const timec &c1,const timec &c2)
{if(c1.h>c2.h)
{a=c1.h-c2.h;}
else a=c2.h-c1.h;
if(c1.m>c2.m)
b=c1.m-c2.m;
else a=c2.m-c1.m;
if (c1.s>c2.s)
c=c1.s-c2.s;
else a=c2.s-c1.s;
return timec(a,b,c);)
ostream &operator<<(ostream &output,const timec &c3)
{if (c3.s>=60)
{b=b-1;
c=c-60;}
   
    if (c3.m>=60)
{a=a+1;
b=b-60;}
    output<<c3.timec(a,b,c)<<" ";
    return ourput;}
int main(int argc, char* argv[])
{timec ab(12,36,23),cd(12,35,22);
timec f(0,0,0);
f=ab+cd;
f.print();
    return 0;
}
搜索更多相关主题的帖子: friend public include 
2011-06-30 19:59
快速回复:为什么出错。。。重载
数据加载中...
 
   



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

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