2012-07-07 21 views
14

मैं इस का उपयोग करते हुए एक संकलन त्रुटि मिलती है:std :: std :: function से बांधें?

std::vector<std::function<int(int)>> functions; 

std::function<int(int, int)> foo = [](int a, int b){ return a + b; }; 
std::function<int(int)> bar = std::bind(foo, 2); 

functions.push_back(bar); 

त्रुटि मैं मिलता है:

/usr/include/c++/4.6/functional:1764:40: error: no match for call to '(std::_Bind<std::function<int(int, int)>(int)>) (int)' 

कोई मुझे बताओ कैसे एक std::function में एक std::bind कन्वर्ट करने के लिए कर सकते हैं?

उत्तर

15
std::function<int(int)> bar = std::bind(foo, 2, std::placeholders::_1); 
+0

'' foo' नहीं, लेकिन उससे अलग है। – Xeo

+0

आपको नामस्थान std :: प्लेसहोल्डर्स का उपयोग करने की भी आवश्यकता है। – juanchopanza

+0

@Xeo ने तय किया कि – inkooboo

संबंधित मुद्दे