我正在玩std :: function和std :: bind的arround,我發現了一些不直觀的東西,我想更好地理解它。瞭解std :: function和std :: bind
例如:
void fun()
{
}
void hun(std::string)
{
}
int main()
{
function<void(int)> g = &fun; //This fails as it should in my understanding.
function<void(int)> f = std::bind(fun); //This works for reasons unknown to me
function<void(int, std::string)> h = std::bind(hun); //this doesn't work
return 0;
}
怎麼可能到function<void(int)>
綁定到一個函數,空隙()。 然後我可以調用f(1)並獲得樂趣()。 我想了解這是如何完成的。 進入微軟Visual Studio 2012的實現這讓我迷失在一堆不可讀的宏。所以我在這裏問這個問題。
我正在使用vs2012 Express版本。 – Alex 2013-04-23 08:50:14
你能推薦這樣的網站嗎? – Alex 2013-04-23 08:52:11
使用_clang_和_g ++ _進行編譯。 +1,有趣的情況。 – soon 2013-04-23 08:52:34