在class中如何從 function pointer 取得 function name? |
尚未結案
|
panda0800
一般會員 發表:4 回覆:5 積分:1 註冊:2003-03-18 發送簡訊給我 |
在 class 中的 function 如何從 function pointer 取得 他的 function name?
ex:
class aa{
int fun1();
int fun2();
}
int aa::fun1() { return 1; }
int aa::fun2()
{
void *p= (void*)fun1; <--此行compiler時語法會出錯,請問如何解決?
AnsiString str=MethodName(p); //want to got the "fun1"
} 發表人 - panda0800 於 2004/08/06 17:31:37
|
pwipwi
版主 發表:68 回覆:629 積分:349 註冊:2004-04-08 發送簡訊給我 |
panda0800你好:
MethodName只能用於TObject衍生的class,而且只在用在property的published method。在code中的用法,應該只會傳回一個空字串。 宣告成員函式指標的方法,可以參考下面的範例:
class A{ public: int return5(void){return 5;} int return6(void){return 6;} }; void __fastcall TForm1::Button1Click(TObject *Sender) { int (A::*get5)(void); int (A::*get6)(void); get5 = A::return5; get6 = A::return6; A objectA; int ia = ((objectA).*(get5))(); //ia = 5 int ib = ((objectA).*(get6))(); //ib = 6 } |
panda0800
一般會員 發表:4 回覆:5 積分:1 註冊:2003-03-18 發送簡訊給我 |
|
panda0800
一般會員 發表:4 回覆:5 積分:1 註冊:2003-03-18 發送簡訊給我 |
|
pwipwi
版主 發表:68 回覆:629 積分:349 註冊:2004-04-08 發送簡訊給我 |
引言: Dear pwipwi sir, Sorry my net has some trouble recently. Thks for your response. But I want to get the function name string "return5" in code. How can I fill the "return5" in the 回傳的"空字串"? Thks. Best regard, Panda0800ㄟ...下面的碼有點無厘頭...但,是不是你要的? #define GetFunctionName(x) #x void __fastcall TForm1::Button1Click(TObject *Sender) { Caption = GetFunctionName(return5); } |
panda0800
一般會員 發表:4 回覆:5 積分:1 註冊:2003-03-18 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |