5

I'm trying to create a vector of std::functions in my logger class. When I try to bind a method to my std::function like that :

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

the add_string function being defined like :

void add_string(string text);

However, gcc (with the gfilt addon to try to understand the template errors) returns :

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
3
  • Is add_string() a member function of NcursesWindows? Commented Feb 9, 2012 at 14:28
  • 1
    Isn't there a placeholder for the string parameter missing in your bind call? In boost you would need bind(&NcursesWindow::add_string,&log_win,_1) Commented Feb 9, 2012 at 14:33
  • yes, this function prototype is taken from the NcursesWindows .h Commented Feb 9, 2012 at 14:36

1 Answer 1

9

Isn't there a placeholder for the string parameter missing in your bind call?

Try this:

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

The member function has two parameters: the hidden this pointer and a std::string. You bind the first to the instance of your class, and the other will stay, therefore the placeholder.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.