typedefvoid(*PEHF)();
class X
{
private:
static PEHF currentPEHF;
public:
static PEHF set_new_handler(PEHF);
void * operatornew(size_t size);
//.... other class specific functions
};
Now, assume that the implementation of the functions above apart from //.... other class specific functions are same and there is absolutely no change. So how can we use templates to write one implemention for all the classes?
AFAIK, you do need inheritance to accomplish the above, but simply deriving from a base class that implements this functionality won't work as the data member and function are static. Try:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
typedefvoid(*PEHF)();
template <class T>
class Base
{
private:
static PEHF currentPEHF;
public:
static PEHF set_new_handler(PEHF p){ currentPEHF = p; return currentPEHF;}
};
template <class T> PEHF Base<T>::currentPEHF;
class A : public Base<A>
{
public:
//.... other class specific functions
};