有什麼辦法可以給C++帶來一些函數式編程,我想把一些LAMBDA函數或者運算符作爲參數傳遞給另一個函數。有沒有一些方法可以提供一些函數或運算符作爲參數?
例如:
void test(DWORD foo)
{
try { __asm { call foo; } } // very weird way, don't think that could work
catch (...) {() }
}
或:
void test2(DWORD foo)
{
someconnection.Open();
__asm { call foo; } // very weird way, don't think that could work
someconnection.Close();
}
和用法一樣:
int main()
{
...
dosomething();
...
void operator()(int n) // lambda expression, not sure if that correct way creating them
{
dosomething();
dosomethingelse();
}
test (*operator(5)) // here is what I want
test2 (*operator(10)) // here is what I want
...
dosomethingelse();
...
}
我使用Visual Studio 2010和不知道如果我可以用C + + 0x那裏,但我可以使用提升,如果這可以做我想做的事情。
那麼有什麼方法可以做到嗎?
谷歌函數指針和增強::函數 – Patrick 2011-03-18 13:10:38