[問題] 沒看過的宣告用法
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++ 6.0
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
no
問題(Question):
struct B
{
int foo( double data );
static int _stdcall bar(double data);
};
typedef int (B::*PFFOO)(double);
PFFOO Foo = &B::foo;
// 這行的 B:: 算是namespace 嗎?? 看起來像是取function foo 的位址
// 可是這行有 instance 嗎??
B Obj;
B* pObj = &Obj
int n2 = (Obj.*Foo) ( 47.11 );
int n3 = (pObj->*Foo) ( 47.11 );
// 以上這兩行不明白怎麼可以這樣用
// Obj. 後面還能接 non-member function??
程式碼(Code):(請善用置底文網頁, 記得排版)
http://ideone.com/NXt2w
補充說明(Supplement):
在 codeproject 看到的
實務上會這樣用嗎??
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.170.120.242
※ 編輯: CumCumCum 來自: 118.170.120.242 (10/02 15:30)
→
10/02 15:34, , 1F
10/02 15:34, 1F
→
10/02 15:37, , 2F
10/02 15:37, 2F
→
10/02 15:38, , 3F
10/02 15:38, 3F
→
10/02 15:38, , 4F
10/02 15:38, 4F
推
10/02 16:50, , 5F
10/02 16:50, 5F
→
10/02 16:51, , 6F
10/02 16:51, 6F
推
10/02 16:52, , 7F
10/02 16:52, 7F
→
10/02 16:52, , 8F
10/02 16:52, 8F
推
10/02 16:54, , 9F
10/02 16:54, 9F
→
10/02 16:55, , 10F
10/02 16:55, 10F
推
10/02 16:55, , 11F
10/02 16:55, 11F
→
10/02 16:55, , 12F
10/02 16:55, 12F
謝謝大家,爬文之後更加清楚了,其實就是shadow大說的,prt to member-func
然後呼叫時,需要 .* or ->* operator 和 instance or ptr to instance 搭配使用
※ 編輯: CumCumCum 來自: 1.165.199.37 (10/03 23:13)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章