求教一个源代码问题,谢谢高手!!!
#include <stdafx.h>#include <iostream>
#include <string>
using namespace std;
class CDate{ //日期类
public:
CDate(int y=2008,int m=9,int d=10); //带默认参数
CDate operator +(const int i); //加运算重载
friend ostream operator <<(ostream& output,CDate & date); //友元
public:
int year,month,day;
};
//day属性的加运算
CDate CDate:perator +(const int i)
{
CDate cd;
cd.year=year;
cd.month=month;
cd.day=day+i;
return cd;
}
//流输出
ostream operator <<(ostream& output,CDate & date)
{
string str;
char ch[10];
str.assign(itoa(date.year,ch,10));
str.append("/");
str.append(itoa(date.month,ch,10));
str.append("/");
str.append(itoa(date.day,ch,10));
return output<<str<<endl;
}
CDate::CDate(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
int main(void)
{
CDate date(1999,9,9);
cout<<date; //重载的输出流
date=date+10; //重载加运算
cout<<date; //重载的输出流
return 0;
}
但是在编译的同时提示有问题:
e:\第16章\ch16_9\ch16_9.cpp(43) : error C2593: 'operator <<' is ambiguous
e:\第16章\ch16_9\ch16_9.cpp(45) : error C2593: 'operator <<' is ambiguous
希望高手能够解答这到底是哪里有问题了?