Boost logo

Boost Users :

Subject: [Boost-users] [thread] About the virtual in virtual operator()
From: Richard Vock (vock_at_[hidden])
Date: 2009-10-30 10:04:42


I don't really know wether this is a Boost.Thread related
question or a general c++ related, but since I couldn't
decide I will disturb you first ;)

Maybe you have the patience to look at this minimalistic
framework (I stripped almost all functionality):

http://pastebin.com/m7dcc833f

This compiles well and running it gives me the expected:

# starting
# This is A
# This is B
# shutting down

The problem is, that I want to run the kernels as threads.
Have (again) a look at the highlighted lines (27-29):

If I replace 27 by 28+29 I (expectedly) get a compile error
since Kernel is abstract. However if I make it non-abstract
by implementing the operator() in it, it is this function
(namely Kernel::operator()) which get's called instead of
TestKernel::operator().

Note that Program will not be able to know about the concrete
child classes of Kernel so it cannot dynamic_cast<ConcretKernel*>
the pointers and I don't want to use maschine-specific ways
like __decltype.

I imagine this is merely the old non-static member function
pointer problem, however I tried dozens of ways to get around
this and the only thing that worked was to add a
ConcreteKernel::run() {
   thread t(*this);
   t.join();
}
to *each* single child class of Kernel which gets rather un-
managable with 50 and more descendants.

I hope that made sense and that I didn't fail that hard,
Richard Vock


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net