• <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>
            華劍緣
            一切都在這個過程中獲得,將那些目標埋藏于心中
            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)執行了"<<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)執行了!"<<endl;
                
            return 0;
            }
            int GridTest::test2(int x, int y){
                cout
            <<"GridTest::test2(int x, int y)執行了!"<<endl;
                
            return 0;
            }
            int GridTest::test3(int x, int y){
                cout
            <<"GridTest::test3(int x, int y)執行了!"<<endl;
                
            return 0;
            }
            int GridTest::test4(int x, int y){
                cout
            <<"GridTest::test4(int x, int y)執行了!"<<endl;
                
            return 0;
            }
            void GridTest::display(){
                cout
            << this->foreach( this->test1, 4, 5); 
            //一直報錯: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上就沒有問題,在Eclipse上編譯就報錯 no matching function for call to `GridTest::foreach(<unknown type>, int, int)'
            }
            posted on 2009-03-09 17:14 華劍緣 閱讀(1592) 評論(5)  編輯 收藏 引用

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

            對于C函數來說,函數名直接表示其函數地址,但是對于成員函數而言,則必須使用&ClassName::memFn才表示該成員函數的地址。gcc對C++語法要求更嚴格。

              回復  更多評論
              
            # re: 求助:關于 C++函數指針, 成員函數指針的問題
            2009-03-09 21:57 | 陳梓瀚(vczh)
            如何通過指針調用成員函數的解決方案:
            class A
            {
            public:
            int Method(int x);
            };

            //1:構造對象A
            A a;
            //2:拿到函數指針
            typedef int (A::*FP)(int);
            FP fp=&A::Method();
            //3:調用
            int result=a.*fp(100);  回復  更多評論
              
            # re: 求助:關于 C++函數指針, 成員函數指針的問題
            2009-03-09 23:10 | 華劍緣
            @Kevin Lynx
            謝謝,果然是這樣.問題解決了  回復  更多評論
              
            # re: 求助:關于 C++函數指針, 成員函數指針的問題
            2009-03-09 23:12 | 華劍緣
            @陳梓瀚(vczh)
            謝謝,講的很清楚.  回復  更多評論
              
            # re: 求助:關于 C++函數指針, 成員函數指針的問題
            2009-03-10 01:49 | 陳梓瀚(vczh)
            @華劍緣
            我認為你應該可以理解為什么《The C++ Programming Language》說“你沒見過->*和.*的話也無所謂”了。  回復  更多評論
              
            色诱久久久久综合网ywww| 色婷婷久久综合中文久久一本| 久久久亚洲欧洲日产国码是AV| 青青草原综合久久大伊人| 久久人妻少妇嫩草AV无码专区 | 亚洲AV伊人久久青青草原| 久久99九九国产免费看小说| 996久久国产精品线观看| 久久国产成人精品国产成人亚洲| 精品一二三区久久aaa片| 久久最新精品国产| 伊人久久久AV老熟妇色| 亚洲欧美久久久久9999| 久久这里只有精品18| 久久久亚洲精品蜜桃臀| 99久久精品午夜一区二区| 国产精品99久久久精品无码| 精品久久久久久久中文字幕 | 久久最新免费视频| 91精品国产综合久久精品| 一本久久a久久精品综合香蕉| 国产精品九九久久免费视频 | 久久亚洲中文字幕精品一区| 一本色道久久88加勒比—综合| 性欧美丰满熟妇XXXX性久久久 | 一本色道久久88综合日韩精品 | 国产精品日韩深夜福利久久| 久久久一本精品99久久精品66| 亚洲国产综合久久天堂| 久久人人爽人人澡人人高潮AV| 国产精品免费久久久久影院 | 国产成人精品综合久久久| 日韩十八禁一区二区久久| 久久精品成人影院| 久久中文精品无码中文字幕| 国产精品美女久久久免费 | 久久人人爽人人爽人人爽 | 99精品国产免费久久久久久下载| 久久久久国产精品麻豆AR影院| 三级韩国一区久久二区综合| 久久笫一福利免费导航|