c++ - Can't pass pointer to derived class function into base class -



c++ - Can't pass pointer to derived class function into base class -

i'm trying pass function derived class base of operations class function expects function pointer, i'm getting compiler error.

[bcc32 error] e2034 cannot convert 'void (bar::*)(int)' 'void (foo::*)(int)'

i guess designed, there way around doesn't involve unpleasant casting? can boost::bind help me here?

#define call_member_fn(object,ptrtomember) ((object).*(ptrtomember)) class foo { public: typedef void (foo::*ffunc)(int i); void test(ffunc f) { call_member_fn(*this,f)(123); } void barf1(int i) {}; }; class bar : public foo { public: void barf2(int i) {}; }; void ffff() { foo f; f.test(foo::barf1); // works bar b; b.test(bar::barf1); // works b.test(bar::barf2); // error }

as side note, have working fine using virtual function, obvious approach rather function pointer, i'm trying working way before attempting boost::bind trickery later...

b.test( ( foo::ffunc )&bar::barf2 );

sorry, didn't mean submit answer, wanted comment. sample code.

edit: well, maybe more "pleasant" casting, since it's c++ style? updated sample.

b.test( static_cast< foo::ffunc >(&bar::barf2) );

c++ boost member-function-pointers

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -