在成員函數部分的示例:Member functions 我們得到了一個結構X:結合成員函數
struct X {
int foo(int);
};
優選的句法
boost::function<int (X*, int)> f;
f = &X::foo;
X x;
f(&x, 5);
便攜式語法
boost::function2<int, X*, int> f;
f = &X::foo;
X x;
f(&x, 5);
個
我的問題是:
- 爲什麼我必須把額外的X *參數時,我INT FOO(INT)只有一個參數?另外,是一樣使用boost ::綁定,如:
人*人=新的Person( 「塗」,23);
boost :: function newFunc2 = boost :: bind(& Person :: printInfo,person);
- 有什麼喜歡的語法和便攜式語法以及何時使用一個比另一個區別?
- 什麼是函數對象?那是函數指針嗎?
1.取決於編譯器,Visual C++在寄存器'ecx' iirc中傳遞'this'。 – Xeo 2011-05-28 12:07:32
@Xeo,很好的電話,我不知道 - 我已經更新了答案,並且鏈接到維基百科中提到它。 – Node 2011-05-28 12:16:51