• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            華劍緣
            一切都在這個(gè)過(guò)程中獲得,將那些目標(biāo)埋藏于心中
            posts - 19,comments - 20,trackbacks - 0
            /*
             * GridTest.h
             *
             *  Created on: 2009-2-27
             *      Author: Administrator
             
            */

            #ifndef GRIDTEST_H_
            #define GRIDTEST_H_

            class GridTest {
                
            static const int x=3,y=4;
            public:
                GridTest();

                
            virtual ~GridTest();
                typedef 
            int (GridTest:: *memberFuncType)(int x, int y);
                
            void display();
                
            int foreach(memberFuncType fn, int i, int j);
                
            int test1(int x, int y);
                
            int test2(int x, int y);
                
            int test3(int x, int y);
                
            int test4(int x, int y);
            };

            #endif /* GRIDTEST_H_ */



            /*
             * GridTest.cpp
             *
             *  Created on: 2009-2-27
             *      Author: Administrator
             
            */

            #include 
            "GridTest.h"
            #include 
            <iostream>
            using namespace std;

            GridTest::GridTest() {
                
            // TODO Auto-generated constructor stub

            }


            GridTest::
            ~GridTest() {
                
            // TODO Auto-generated destructor stub
            }

            int GridTest::foreach(memberFuncType fn, int x, int y){
                cout
            <<"GridTest::foreach(memberFuncType fn, int x, int y)執(zhí)行了"<<endl;
                cout
            <<"fn(x,y)"<<(this->*fn)(x, y);
                
            return (this->*fn)(x, y);
            }

            int GridTest::test1(int x, int y){
                cout
            <<"GridTest::test1(int x, int y)執(zhí)行了!"<<endl;
                
            return 0;
            }
            int GridTest::test2(int x, int y){
                cout
            <<"GridTest::test2(int x, int y)執(zhí)行了!"<<endl;
                
            return 0;
            }
            int GridTest::test3(int x, int y){
                cout
            <<"GridTest::test3(int x, int y)執(zhí)行了!"<<endl;
                
            return 0;
            }
            int GridTest::test4(int x, int y){
                cout
            <<"GridTest::test4(int x, int y)執(zhí)行了!"<<endl;
                
            return 0;
            }
            void GridTest::display(){
                cout
            << this->foreach( this->test1, 4, 5); 
            //一直報(bào)錯(cuò):no matching function for call to `GridTest::foreach(<unknown type>, int, int)'
            }

            int main()
            {
                GridTest 
            *grid;
                grid
            = new GridTest();
                grid
            ->display();
                
            return 0;
            }

            這段代碼在VC6.0上就沒(méi)有問(wèn)題,在Eclipse上編譯就報(bào)錯(cuò) no matching function for call to `GridTest::foreach(<unknown type>, int, int)'
            }
            posted on 2009-03-09 17:14 華劍緣 閱讀(1598) 評(píng)論(5)  編輯 收藏 引用

            FeedBack:
            # re: 求助:關(guān)于 C++函數(shù)指針, 成員函數(shù)指針的問(wèn)題
            2009-03-09 17:52 | Kevin Lynx
            cout << this->foreach( this->test1, 4, 5);
            改為:
            cout << this->foreach( &GridTest::test1, 4, 5);

            對(duì)于C函數(shù)來(lái)說(shuō),函數(shù)名直接表示其函數(shù)地址,但是對(duì)于成員函數(shù)而言,則必須使用&ClassName::memFn才表示該成員函數(shù)的地址。gcc對(duì)C++語(yǔ)法要求更嚴(yán)格。

              回復(fù)  更多評(píng)論
              
            # re: 求助:關(guān)于 C++函數(shù)指針, 成員函數(shù)指針的問(wèn)題
            2009-03-09 21:57 | 陳梓瀚(vczh)
            如何通過(guò)指針調(diào)用成員函數(shù)的解決方案:
            class A
            {
            public:
            int Method(int x);
            };

            //1:構(gòu)造對(duì)象A
            A a;
            //2:拿到函數(shù)指針
            typedef int (A::*FP)(int);
            FP fp=&A::Method();
            //3:調(diào)用
            int result=a.*fp(100);  回復(fù)  更多評(píng)論
              
            # re: 求助:關(guān)于 C++函數(shù)指針, 成員函數(shù)指針的問(wèn)題
            2009-03-09 23:10 | 華劍緣
            @Kevin Lynx
            謝謝,果然是這樣.問(wèn)題解決了  回復(fù)  更多評(píng)論
              
            # re: 求助:關(guān)于 C++函數(shù)指針, 成員函數(shù)指針的問(wèn)題
            2009-03-09 23:12 | 華劍緣
            @陳梓瀚(vczh)
            謝謝,講的很清楚.  回復(fù)  更多評(píng)論
              
            # re: 求助:關(guān)于 C++函數(shù)指針, 成員函數(shù)指針的問(wèn)題
            2009-03-10 01:49 | 陳梓瀚(vczh)
            @華劍緣
            我認(rèn)為你應(yīng)該可以理解為什么《The C++ Programming Language》說(shuō)“你沒(méi)見(jiàn)過(guò)->*和.*的話也無(wú)所謂”了。  回復(fù)  更多評(píng)論
              

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            亚洲午夜无码久久久久| 久久最新免费视频| 久久99精品久久久久久hb无码 | 久久午夜夜伦鲁鲁片免费无码影视 | 久久精品国产亚洲av麻豆小说| 久久久久久九九99精品| 国产精品九九久久免费视频 | 久久久WWW免费人成精品| 一级做a爰片久久毛片毛片| 一本色综合网久久| 99久久精品无码一区二区毛片| 久久男人中文字幕资源站| 亚洲国产精品成人久久| 久久久国产精华液| 99久久精品国内| 一本色道久久综合亚洲精品| 久久国产热这里只有精品| 日产精品久久久一区二区| 久久毛片免费看一区二区三区| 97久久国产亚洲精品超碰热| 久久受www免费人成_看片中文| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 国产三级精品久久| 久久亚洲欧美国产精品| 少妇被又大又粗又爽毛片久久黑人| 久久精品国产精品青草| 久久精品一本到99热免费| 国产成人无码精品久久久性色| 久久久人妻精品无码一区| 久久激情亚洲精品无码?V| 国产成人无码精品久久久久免费| 成人妇女免费播放久久久| 国产精品一久久香蕉国产线看观看| 久久亚洲精品无码aⅴ大香| 亚洲日韩欧美一区久久久久我| 久久天天日天天操综合伊人av| 久久久精品日本一区二区三区| 久久精品无码av| 久久精品国产亚洲AV影院| 亚洲av伊人久久综合密臀性色| 久久精品a亚洲国产v高清不卡|