亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 請(qǐng)教關(guān)于C++重載的問(wèn)題 [打印本頁(yè)]

作者: sdupoplar    時(shí)間: 2003-06-27 16:27
標(biāo)題: 請(qǐng)教關(guān)于C++重載的問(wèn)題
#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
按以上的程序可通過(guò)。輸出結(jié)果為:X==10 Y==20;
但是當(dāng)使用 帶有 //*的行編譯的時(shí)候出現(xiàn)以下錯(cuò)誤:
D:\experiment\experiment.cpp(31) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.
experiment.exe - 1 error(s), 0 warning(s)

本人對(duì)STL涉獵不深,請(qǐng)教各位大蝦問(wèn)題出在那里???
作者: 無(wú)雙    時(shí)間: 2003-06-27 17:43
標(biāo)題: 請(qǐng)教關(guān)于C++重載的問(wèn)題
我這里沒(méi)問(wèn)題
使用的是bcb6
作者: Neoking    時(shí)間: 2003-06-27 22:54
標(biāo)題: 請(qǐng)教關(guān)于C++重載的問(wèn)題
哦!!你第一導(dǎo)入<iostream>;包時(shí),你用的是"iostream",我剛開(kāi)始學(xué),不過(guò)我以為應(yīng)該是"iostream.h"
作者: 山少爺    時(shí)間: 2003-06-27 23:50
標(biāo)題: 請(qǐng)教關(guān)于C++重載的問(wèn)題
兩個(gè)都是可以的。在C++的發(fā)展過(guò)程中,不同的編譯器廠商可能用了不同的文件擴(kuò)展名。為了消除差別,C++標(biāo)準(zhǔn)去除了擴(kuò)展名。
作者: 水餃    時(shí)間: 2003-06-30 14:03
標(biāo)題: 請(qǐng)教關(guān)于C++重載的問(wèn)題
我用的也是vc6.0,但是編譯你的程序沒(méi)有任何問(wèn)題。
我想可能是你的vc6沒(méi)有打過(guò)補(bǔ)丁。你打上Pack5試試。
作者: fightxxx    時(shí)間: 2003-07-02 11:19
標(biāo)題: 請(qǐng)教關(guān)于C++重載的問(wèn)題
pack5是什么東東??
作者: 水餃    時(shí)間: 2003-07-04 17:26
標(biāo)題: 請(qǐng)教關(guān)于C++重載的問(wèn)題
補(bǔ)丁。微軟的網(wǎng)站上有下的。
作者: Neoking    時(shí)間: 2003-07-04 20:06
標(biāo)題: 請(qǐng)教關(guān)于C++重載的問(wèn)題
你既然定義了
friend ostream& operator<<(std:stream &os,const TCox &t) //*
是友元,你為什么寫(xiě)成
std:stream& operator<<(std:stream &os,const TCox &t) //*
!!好好看看友元的書(shū)!我認(rèn)為是這樣,如果錯(cuò)了別賴我!
作者: 星月無(wú)痕    時(shí)間: 2003-07-04 22:33
標(biāo)題: 請(qǐng)教關(guān)于C++重載的問(wèn)題
不會(huì)




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2