大家帮忙看看,在结果在CB上能正常通过,在VC上运行却出现一个错误
Compiling...
cc.cpp
F:\vc\myvc++code\cc\cc.cpp(49) : error C2593: 'operator <<' is ambiguous
执行 cl.exe 时出错.想不通,麻烦大家看看到底VC哪些地方不支持,还是程序本身有问题,谢谢拉!!!!
#include<iostream>
#include<iomanip>
using namespace std;
//-------------------------------------------------
class Date
{
public:
int year, month, day;
public:
Date(int y=2000,int m=1, int d=1);
Date(const string& s);
bool isLeapYear()const;
friend ostream& operator<<(ostream& o, const Date& d);
};
//----------------------
Date::Date(const string& s)
{
year = atoi(s.substr(0,4).c_str());
month = atoi(s.substr(5,2).c_str());
day = atoi(s.substr(8,2).c_str());
}
//-----------------------------------
Date::Date(int y, int m, int d){year=y,month=m,day=d;}
//---------------------------------------
bool Date::isLeapYear()const
{
return (year % 4==0 && year % 100)||year % 400==0;
}
//--------------------------------
ostream& operator<<(ostream& o, const Date& d)
{
o<<setfill('0')<<setw(4)<<d.year<<'-'<<setw(2)<<d.month<<'-';
return o<<setw(2)<<d.day<<'\n'<<setfill(' ');
}
//-------------------------------------------------
int main(int argc, char* argv[])
{
Date c("2005-12-28");
Date d(2003,12,6);
Date e(2000);
Date f(2000,12);
Date g;
cout<<c<<d<<e<<f<<g;
return 0;
}其实我以前也出现过这种情况,后来打个补丁就好了,
昨天重装了一下操作系统,后来又去给VC打补丁,SP5,SP6都 打了,可又回到以前那个编译错误了,
难道 是我补丁打错了地方???
下载后直接放到VC根目录下,然后点那SP6exe,就开始装了,它自动选了C目录下装上后重启了一次,
扑丁应该打一了,因为在VC的Help->about vc++里显示了打了SP6补丁后的版本信息大家看,这有什么问题,
真是烦,程序没编几个,调VC环境却花了不少时间
Compiling...
cc.cpp
F:\vc\myvc++code\cc\cc.cpp(49) : error C2593: 'operator <<' is ambiguous
执行 cl.exe 时出错.想不通,麻烦大家看看到底VC哪些地方不支持,还是程序本身有问题,谢谢拉!!!!
#include<iostream>
#include<iomanip>
using namespace std;
//-------------------------------------------------
class Date
{
public:
int year, month, day;
public:
Date(int y=2000,int m=1, int d=1);
Date(const string& s);
bool isLeapYear()const;
friend ostream& operator<<(ostream& o, const Date& d);
};
//----------------------
Date::Date(const string& s)
{
year = atoi(s.substr(0,4).c_str());
month = atoi(s.substr(5,2).c_str());
day = atoi(s.substr(8,2).c_str());
}
//-----------------------------------
Date::Date(int y, int m, int d){year=y,month=m,day=d;}
//---------------------------------------
bool Date::isLeapYear()const
{
return (year % 4==0 && year % 100)||year % 400==0;
}
//--------------------------------
ostream& operator<<(ostream& o, const Date& d)
{
o<<setfill('0')<<setw(4)<<d.year<<'-'<<setw(2)<<d.month<<'-';
return o<<setw(2)<<d.day<<'\n'<<setfill(' ');
}
//-------------------------------------------------
int main(int argc, char* argv[])
{
Date c("2005-12-28");
Date d(2003,12,6);
Date e(2000);
Date f(2000,12);
Date g;
cout<<c<<d<<e<<f<<g;
return 0;
}其实我以前也出现过这种情况,后来打个补丁就好了,
昨天重装了一下操作系统,后来又去给VC打补丁,SP5,SP6都 打了,可又回到以前那个编译错误了,
难道 是我补丁打错了地方???
下载后直接放到VC根目录下,然后点那SP6exe,就开始装了,它自动选了C目录下装上后重启了一次,
扑丁应该打一了,因为在VC的Help->about vc++里显示了打了SP6补丁后的版本信息大家看,这有什么问题,
真是烦,程序没编几个,调VC环境却花了不少时间
friend ostream& operator<<(ostream& o, const Date& d);
这个去掉试试看呢
去掉friend ostream& operator<<(ostream& o, const Date& d);可以