2012-02-09 13 views
5

के साथ कार्यों के लिए C++ में std bind का उपयोग मैं अपने लॉगर क्लास में std :: फ़ंक्शंस का वेक्टर बनाने की कोशिश कर रहा हूं। जब मैं उस तरह मेरे एसटीडी के लिए एक विधि :: समारोह बाध्य करने के लिए प्रयास करें: समझने की कोशिश करने के लिए gfilt ऐड-ऑन के साथ (एक तर्क (स्ट्रिंग)

void add_string(string text); 

हालांकि, जीसीसी:

NcursesWindow log_win("Logs",LINES-1,COLS/3,0,COLS*2/3); 
std::function<void(std::string)> f = std::bind(&NcursesWindow::add_string,&log_win); 

add_string समारोह की तरह परिभाषित किया जा रहा टेम्पलेट त्रुटियों) देता है:

BD Software STL Message Decryptor v3.10 for gcc 2/3/4 
In file included from ./inc/ncursesui.h:6:0, 
from src/ncursesui.cpp:1: 
functional: In static member function ‘static void _Function_handler< 
    void({basic_string<char>} ...), _Bind< 
     _Mem_fn<void (NcursesWindow::*)(basic_string<char>)>(
      NcursesWindow)> 
>::_M_invoke(const _Any_data &, {basic_string<char>} ...)’: 
[STL Decryptor: Suppressed 1 more STL standard header message] 
src/ncursesui.cpp:32:86: instantiated from here 
functional:1778:2: erreur: no match for call to ‘(
    _Bind< 
     _Mem_fn<void (NcursesWindow::*)(basic_string<char>)>(
      NcursesWindow)>) (basic_string<char>)’ 

STL Decryptor reminders: 
Use the /hdr:L option to see all suppressed standard lib headers 
Use the /cand:L option to see all suppressed template candidates 
+0

'add_string()' 'NcursesWindows' का सदस्य फ़ंक्शन है? – liwp

+1

क्या आपके बाइंड कॉल में अनुपलब्ध स्ट्रिंग पैरामीटर के लिए कोई प्लेसहोल्डर नहीं है? बूस्ट में आपको 'बाइंड (& NcursesWindow :: add_string, और log_win, _1) ' – nabulke

+0

हां की आवश्यकता होगी, यह फ़ंक्शन प्रोटोटाइप NcursesWindows से लिया जाता है। – Tuxer

उत्तर

9

वहाँ string पैरामीटर अपने बाँध कॉल में लापता के लिए एक प्लेसहोल्डर नहीं है?

इस प्रयास करें:

bind(&NcursesWindow::add_string,&log_win,std::placeholders::_1); 

सदस्य समारोह दो पैरामीटर है: छिपा this संकेतक और एक std::string। आप अपनी कक्षा के उदाहरण के लिए पहले बाध्य करते हैं, और दूसरा प्लेसहोल्डर रहेंगे।

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