大家帮忙看看,在结果在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环境却花了不少时间

解决方案 »

  1.   

    VC2005通过。把
    friend ostream& operator<<(ostream& o, const Date& d);
    这个去掉试试看呢
      

  2.   

    去掉 friend 不行
    去掉friend ostream& operator<<(ostream& o, const Date& d);可以
      

  3.   

    看不出什么错误,重栽应该就是这么做的如果实在搞不定先放一放吧,应该不是程序的问题说不定以后会有偶然的机会就找到解决办法了,程序没编几个,调VC环境却花了不少时间呵呵,不要管那么多VC环境的问题
      

  4.   

    果然。应该说是VC6对C++标准的支持上的问题吧