2012-02-09 8 views
5

Próbuję utworzyć wektor std :: functions w mojej klasie rejestratora. Kiedy próbuję powiązać metodę moim std :: funkcję tak:użycie std bind w C++ dla funkcji z argumentem (ciągiem znaków)

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); 

funkcję add_string są zdefiniowane następująco:

void add_string(string text); 

Jednak gcc (z dodatku gfilt próbować zrozumieć błędy template) zwraca:

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

Czy 'add_string()' jest funkcją składową 'NcursesWindows'? – liwp

+1

Czy w wywołaniu powiązania nie ma symbolu zastępczego dla parametru tekstowego? W boostie potrzebujesz 'bind (& NcursesWindow :: add_string, & log_win, _1)' – nabulke

+0

tak, ten prototyp funkcji pochodzi z NcursesWindows .h – Tuxer

Odpowiedz

9

nie jest symbolem zastępczym dla parametru string brakującego w wywołaniu wiążą?

Spróbuj tego:

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

Funkcja członek ma dwa parametry: ukryte this wskaźnik i std::string. Wiążesz pierwszą z instancją swojej klasy, a druga pozostanie, a więc symbol zastępczy.

Powiązane problemy