boost::bind with derivated class
Hello, I'm using boost::bind for binding parameters to a method for calling a thread group: myclass::mymethod( const mysuperclass& myobj ) { bost::threadgroup mythreads; mythreads.create_thread( boost::bind( &myclass::mythreadmethod, this, boost::ref(myobj) ) ); } myclass::mythreadmethod( const mysuperclass myobj ) {} // I need a copy of the object, so I don't set the reference operator & mysuperclass is a pure virtual class. Now I create a derivate class with class myderivate : public mysuperclass {} and call myderivate y; myclass x; x.mymethod( y ); The compiler breaks with the error, that myobj is a class with pure virtual methods. How I can call the bind methods with the correct object? myobj is an object of the derivated class so I would "send them" to the methods. Thanks Phil
myclass::mythreadmethod( const mysuperclass myobj ) {} // I need a copy of the object, so I don't set the reference operator & mysuperclass is a pure virtual class. Now I create a derivate class with class myderivate : public mysuperclass {} and call myderivate y; myclass x; x.mymethod( y ); The compiler breaks with the error, that myobj is a class with pure virtual methods. How I can call the bind methods with the correct object? myobj is an object of the derivated class
No, it isn't of the derived class, it's an instance of the abstract base. When you pass an object by value, it gets "sliced". It's unrelated to Boost.Bind, it's just c++ rule.
Am 24.09.2011 um 18:08 schrieb Igor R:
myclass::mythreadmethod( const mysuperclass myobj ) {} // I need a copy of the object, so I don't set the reference operator & mysuperclass is a pure virtual class. Now I create a derivate class with class myderivate : public mysuperclass {} and call myderivate y; myclass x; x.mymethod( y ); The compiler breaks with the error, that myobj is a class with pure virtual methods. How I can call the bind methods with the correct object? myobj is an object of the derivated class
No, it isn't of the derived class, it's an instance of the abstract base. When you pass an object by value, it gets "sliced". It's unrelated to Boost.Bind, it's just c++ rule.
Thanks for the hint, I will change my code Phil
participants (2)
-
Igor R
-
Kraus Philipp