- 論壇徽章:
- 0
|
#include "stdafx.h"
#include "iostream.h" //#
//#include "string" //*
//#include "iostream" //*
//using namespace std; //*
class TCox
{
public:
int tc_x,tc_y;
// string str; //*
public:
TCox():tc_x(0),tc_y(0){ }
TCox(int x,int y):tc_x(x),tc_y(y){}
friend ostream& operator<<(ostream &os,const TCox &t); //#
// friend std: stream& operator<<(std: stream &os,const TCox &t); //*
// std: stream& operator<<(std: stream &os){return os<<tc_x;}
};
ostream& operator<<(ostream &os,const TCox &t) //#
//std: stream& operator<<(std: stream &os,const TCox &t) //*
{
os<<"x=="<<t.tc_x<<endl;
os<<"y=="<<t.tc_y<<endl;
return os;
}
int main(int argc, char* argv[])
{
TCox p(10,20);
std::cout<<p<<endl;
return 0;
}
編譯環(huán)境:VC6.0
按以上的程序可通過。輸出結(jié)果為:X==10 Y==20;
但是當使用 帶有 //*的行編譯的時候出現(xiàn)以下錯誤:
D:\experiment\experiment.cpp(31) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.
experiment.exe - 1 error(s), 0 warning(s)
本人對STL涉獵不深,請教各位大蝦問題出在那里??? |
|