Boost::thread - problems with inheritance

Started by
10 comments, last by GoldenArm 10 years, 8 months ago
Quote:Original post by Red Ant
I'm suspecting that no matter how much you try to cheat by using boost::ref to pass a functor to boost::thread's constructor, internally it will still at some point make a copy of the functor, and when that happens, it won't have a clue that you're really passing a derived thread object and not a BaseThreadObject. Hence it will store a copy of the BaseThreadObject part of the class instance you're passing it. The result -> slicing (google it).


I suggest the following.


*** Source Snippet Removed ***

But beware that you may run into object life time issues if your BaseThreadObject instance gets deleted while your thread is still running (and hence potentially accessing your BaseThreadObject instance).


Thanks you for the post.

__________________
Watch Grown Ups Online Free
Advertisement

You guys are genius !!! Was struggling with getting my thread encapsulation done properly, that functor method in a struct of a base class did the job !!!

thanks

This topic is closed to new replies.

Advertisement