Quote:Original post by zyrolasting
Nullsquared had the idea closest to what I was looking for, although I admit I don't fully understand how to implement it. It sounds like a modified Pimpl.
Basically, something like this:
// declare an interface for bar'sstruct barBase{ virtual void policy1() = 0; virtual void policy2() = 0; // etc.};void doStuff(barBase &b){ b.policy1();}// a specific type of bartemplate<typename A, typename B>struct bar: barBase{ // implement the functions};doStuff(bar<int, int>()); // call doStuff with a specific type of bar
If you need the return types to be different between barBase and a class that implements barBase, look into covariant return types: http://en.wikipedia.org/wiki/Covariant_return_type
If you need the parameter types to be different between barBase and a class that implements barBase, you can either use void* or boost::any as the parameters, since you'll know what you have to cast to inside the class that implements barBase. I personally suggest using boost::any since it retains type info over void*, but if you're mostly using pointers and wish to avoid boost::any, then void* is fine.