[Home]CommonCompilerErrorsWhenUsingFunctionAndBindToReplaceCppBuilderClosures

BOOST WIKI | RecentChanges | Preferences | Page List | Links List

Difference (from prior major revision) (no other diffs)

Added: 43a44,48

Cannot convert _bi::bind_t<...>...
The line number for this error is misleading (somewhere in boost/bind.hpp). The problem is that the function signature may not be an exact match. Bcc32 seems to want to include top-level cv-qualifications in this evalutation (I think it's wrong to do so, but I don't have the time to see for sure). For example:
void timer_event(timer * const);
t.OnTimer = bind(&timer_event, _1); // will generate this error

Borland C++ has the concept of closures (with syntactic extensions, including the keyword _closure). The Boost Function and Bind libraries allow the replacement of closures with portable equivalents. The following is a short list of common compiler errors that I ran into while translating my code that used Borland closures into the Boost equivalents.

For the purpose of this page, I'll use the following code in my examples:

 struct timer { boost::function<void, timer *> OnTimer; };
 struct event_handler { void timer_event(timer *); void another_event(timer *, int); };
 timer t;
 event_handler handler;

Call of nonfunction in ... The line number for this error is misleading (somewhere in boost/function/function_template.hpp). The problem is that objects of boost::function<...> type cannot be initialized to 0. You'll have to search through your code to find where something like this occurs:

 timer::timer() : OnTimer(0) { ... }

Could not find a match for boost::get_pointer<T>(const event_handler) ... The line number for this error is misleading (somewhere in boost/mem_fn.hpp). The problem is that the first parameter of a member function must be bound to a pointer or placed in a call to boost::ref:

 bind(&event_handler::timer_event, &handler, _1); // OK
 bind(&event_handler::timer_event, ref(handler), _1); // OK
 bind(&event_handler::timer_event, handler, _1); // generates this error

Could not find a match for bind<>(T, ...) ... (Correct line number). This error indicates some problem with the number or types of the parameters to bind:

Check to make sure your first argument to bind is correct:

 bind(&event_handler::timer_event, ...); // OK
 bind(event_handler::timer_event, ...); // T will be the return type of event_handler::timer_event, in this case, void
 bind(timer_event, ...); // same error as line above
 bind(&timer_event, ...); // T will be some _closure type
If the first argument type is correct (i.e., T is a member function pointer), check the number of free arguments:
 bind(&event_handler::timer_event, &handler, _1); // OK
 bind(&event_handler::timer_event, &handler); // will generate this error
 bind(&event_handler::timer_event, &handler, _1, _2); // will generate this error
Also double-check the signature of event_handler::timer_event to make sure you're defining it with the correct number of arguments:
 bind(&event_handler::another_event, &handler, _1); // if 'another_event' was really supposed to take an argument...

Illegal structure operation ... (Correct line number). Boost functions can be tested in an if statement, but not as part of a logical expression:

 if (OnTimer)
   OnTimer(); // OK
 if (time_ == 0 && OnTimer)
   OnTimer(); // will generate this error

operator+ not implemented in type list... The line number for this error is misleading (somewhere in boost/bind.hpp). The actual problem is that the number of arguments of the member function pointer matches the number of arguments in the call to bind, but is greater than the number of arguments expected by function:

 t.OnTimer = bind(&event_handler::another_event, &handler, _1, _2); // will generate this error

Cannot convert _bi::bind_t<...>... The line number for this error is misleading (somewhere in boost/bind.hpp). The problem is that the function signature may not be an exact match. Bcc32 seems to want to include top-level cv-qualifications in this evalutation (I think it's wrong to do so, but I don't have the time to see for sure). For example:

 void timer_event(timer * const);
 t.OnTimer = bind(&timer_event, _1); // will generate this error

BOOST WIKI | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited October 29, 2001 2:00 pm (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers