I have class with member functions:
typedef std::function<bool (const std::string &)> InsertFunction;
bool insertSourceFile( const std::string & );
bool insertSourceDir( const std::string & );
bool insertHeaderFile( const std::string & );
bool insertHeaderDir( const std::string & );
I'd like to have a reference to one of these InsertFunction
s in another class, and use it to do its job (without having to make classes for each of these functions). I tried using the class constructor and std::bind
to bind the member function's implicit first argument to a pointer of the object in question:
new ListParser( p_target->sourceDirs(), bind(&Target::insertSourceFile, p_target, _1), this );
with
ListParser::ListParser( const stringSet &dirs, const InsertFunction &insert,
State* parent = 0 )
: ParserState( parent ),
m_dirs( dirs ),
m_insert( insert )
{ }
UPDATE: thanks to @lijie, the source now compiles, but when the function m_insert is called, a std::exception
is thrown for std::bad_function_call
. What could be wrong? Thanks! If you need more info, please ask!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…