33,319
社区成员
 发帖
 与我相关
 我的任务
 分享
#include <iostream>
using namespace std;
class time
{
private:
	int hour;
	int minute;
public:
	time();
	time(int h,int m){hour=h;minute=m;}
	time operator+(const time& t);
	time operator-(const time& t);
	time operator*(const double d);
	friend time operator*(const double d,time& t);
	friend ostream& operator<<(ostream& os,const time& t);
};
//省略其他函数定义......
ostream& operator<<(ostream& os,const time& t)
{
	os<<t.hour<<":"<<t.minute;
	return os;
}
#include <iostream>
using namespace std;
namespace COM
{
class Time
{
private:
    int hour;
    int minute;
public:
    Time(){}
    Time(int h,int m){hour=h;minute=m;}
    Time operator+(const Time& t);
    Time operator-(const Time& t);
    Time operator*(const double d);
    friend Time operator*(const double d,Time & t);
    friend ostream& operator<<(ostream& os,const Time& t);
};
//make it as a member of namespace 
ostream& operator<<(ostream& os,const COM::Time& t)
{
    os<<t.hour<<":"<<t.minute;
    return os;
}
}//end of namespace COM
int main()
{
  COM::Time t;
  std::cout << t << std::endl;
  return 0;
}