You seem to have a problem with A being a template argument of do_work in class A: this doesn't actually make sense.
You seem to have a problem with A being a template argument of do_work in class A: this doesn't actually make sense. R is not defined anywhere in B or C and your specialisation syntax is wrong. Do_work will not be polymorphic as it is not virtual, so if you have a collection of A pointers it will only ever call the A version, never the B or C one, even if they are better matches.
Sorry for the bad syntax I just have no idea how to actually code it so I just threw something together to best illustrate what I want to happen in the end. – Talguy Oct 19 '10 at 14:18.
I'm all for using template programming for efficiency and generality, but perhaps you should implement this with virtual functions first. I find it helpful to get something working cleanly and correcting before writing a templated version. Folks here may give you a better answer as well if you have a working non template function.
Besides, if you are going to call this via a callback or pointer to function, you will lose the perf that I think you are trying to gain with a template based solution.
I guess I could do something like this virtual void do_work(void *retrn, void *param)=0; and declare the proper casting and functionality inside the derived classes – Talguy Oct 19 '10 at 15:03 All I'm suggesting is that you look at the functionality first and get something working, before applying templates. I've found this makes it easier and I think you'll get specific feedback here if you edit your response with a working solution. – Rick Oct 19 '10 at 17:27 Using void * may or may not be the right thing to do, it probably is not, but if it is you probably want to make it private and get a public templated function to do the casting then call the method.
That makes the class at least type-safe for users. – CashCow Oct 20 '10 at 9:42.
I ended making two helper classes, a consumer class and producer class that inherit the base class. The base class contains a enum define define whether the derived classes are what functionality. This enum value is set during the base class constructor call.
The helper classes contain the appropriate version of the virtual do_work function that I want (one void w/ some input type and one some return type). When these objects are placed in the container they are casted as the base class and when they are launched in the appropriate generic thread worker function they are either casted to the producer helper class or consumer helper class.
I'm all for using template programming for efficiency and generality, but perhaps you should implement this with virtual functions first. I find it helpful to get something working cleanly and correcting before writing a templated version.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.