線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:827
推到 Plurk!
推到 Facebook!

Template 使用疑問

缺席
Fm
初階會員


發表:19
回覆:66
積分:37
註冊:2003-10-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-03-12 11:04:06 IP:61.62.xxx.xxx 未訂閱
Dear all:     目前在練習template的使用方式..自定義了一個class,,然後做了一個做加法運算的template,用來加自己定義的class,....but編譯就掛了 錯誤訊息: //d:\Code\T3\T3.cpp(31): error C2678: 二元運算子 '+' : 找不到使用左方運算元型別 'const CMyData' 的運算子 (或是沒有可接受的轉換) //    ..我的程式如下.謝謝你:     
 
#include 
#include 
#include 
#include 
using namespace std;
class CMyData
{
public:
        CMyData(const double& tx=0,const double& ty=0):_x(tx),_y(ty){}
    ~CMyData(){}
        bool operator< (const CMyData& ml)const{return this->_y_y
struct plus{
        T operator()(const T& x, const T& y)const{return x y;}
};    template 
struct minus{
        T operator()(const T& x, const T& y)const{return x-y;}
};    int _tmain(int argc, _TCHAR* argv[])
{
        plus plusObj;
        //minus minusObj;
        cout<
//-------------------- Begin with the end in mind.
Fm
初階會員


發表:19
回覆:66
積分:37
註冊:2003-10-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-03-12 14:49:37 IP:61.62.xxx.xxx 未訂閱
改掉紅色的地方....程式就ok了... 這會市我要的嗎?..疑惑中    //--------- #include  #include #include #include using namespace std; class CMyData { public: CMyData(const double& tx=0,const double& ty=0):_x(tx),_y(ty){} ~CMyData(){} bool operator< (const CMyData& ml)const{return this->_y_y struct plus{ T operator()(T& x, T& y){return x y;} }; template struct minus{ T operator()(T& x, T& y){return x-y;} }; int _tmain(int argc, _TCHAR* argv[]) { plus plusObj; cout< //-------------------- Begin with the end in mind.
系統時間:2024-05-19 18:33:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!