建立回傳函式指標的Property |
缺席
|
tkulimi
一般會員 發表:2 回覆:4 積分:1 註冊:2004-11-16 發送簡訊給我 |
我想建立回傳函式指標 Array的property
說明如下 1.以下為int Array型態的property [code cpp] class cSampleDef { private: int m_nAry[10]; int __fastcall nGetA(const int& nIndex) { if(nIndex>=0&&nIndex<10) return m_nAry[nIndex]; else return 0; } void__fastcall vSetA(const int& nIndex,const int& nValue) { if(nIndex>=0&&nIndex<10) m_nAry[nIndex] = nValue; } public: property int nA[int nIndex]={read = nGetA,write = vSetA}; }; [/code] 2.以下做成函式指標的property [code cpp] class cSampleDef { private: void __fastcall (__closure *m_pFun)(); public: __property void __fastcall (__closure *pCallBack)() = {read = m_pFun, write = m_pFun}; }; [/code] 若是想要做成函式指標 Array的property該如何宣告? class cSampleDef { private: void __fastcall (__closure *m_pFun[10])();//10個函式指標陣列,該如何實做可以如第一個根據Index回傳或是寫入? public: //錯誤宣告__property ?={read = ?,write = ?} ; }; 已經有試出來了,以下是Sample class cSampleDef { private: void __fastcall (__closure * m_pGrabDoneFun[4])(); void __fastcall (__closure * __fastcall pFunGetGrabDone(const int& nPort))() { if(nPort < 0 || nPort > 3) { return NULL; } return m_pGrabDoneFun[nPort]; } void __fastcall vSetGrabDoneFun( const int& nPort, void __fastcall (__closure * pFun)()) { if(nPort < 0 || nPort > 3) { return; } } public: __property void __fastcall (__closure * pGrabDone[int nPort])() = {read = pFunGetGrabDone, write = vSetGrabDoneFun}; }; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |