#include <stdio.h>
class TraitsBase{
protected:
typedef void (TraitsBase::*fptr)();
fptr ptr;
TraitsBase(fptr p) : ptr(p){}
public:
void func1(){
printf("func1\n");
}
void func2(){
printf("func2\n");
}
void call(){
(this->*ptr)();
}
};
template<class T> class Traits;
template<> class Traits<int> : public TraitsBase{
public:
Traits<int>() : TraitsBase(&TraitsBase::func1){};
};
template<> class Traits<float>: public TraitsBase{
public:
Traits<float>() : TraitsBase(&TraitsBase::func2){}
};
int main(){
Traits<int> i;
i.call();
Traits<float> f;
f.call();
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgoKY2xhc3MgVHJhaXRzQmFzZXsKcHJvdGVjdGVkOgogICAgCgogICAgdHlwZWRlZiB2b2lkIChUcmFpdHNCYXNlOjoqZnB0cikoKTsKICAgIGZwdHIgcHRyOwogICAgVHJhaXRzQmFzZShmcHRyIHApIDogcHRyKHApe30KcHVibGljOgogICAgdm9pZCBmdW5jMSgpewogICAgICAgIHByaW50ZigiZnVuYzFcbiIpOwogICAgfQogICAgdm9pZCBmdW5jMigpewogICAgICAgIHByaW50ZigiZnVuYzJcbiIpOwogICAgfQogICAgCiAgICB2b2lkIGNhbGwoKXsKICAgICAgICAodGhpcy0+KnB0cikoKTsKICAgIH0KfTsKdGVtcGxhdGU8Y2xhc3MgVD4gY2xhc3MgVHJhaXRzOwp0ZW1wbGF0ZTw+IGNsYXNzIFRyYWl0czxpbnQ+IDogcHVibGljIFRyYWl0c0Jhc2V7CnB1YmxpYzoKICAgIFRyYWl0czxpbnQ+KCkgOiBUcmFpdHNCYXNlKCZUcmFpdHNCYXNlOjpmdW5jMSl7fTsKICAgIAp9Owp0ZW1wbGF0ZTw+IGNsYXNzIFRyYWl0czxmbG9hdD46IHB1YmxpYyBUcmFpdHNCYXNlewpwdWJsaWM6CiAgICBUcmFpdHM8ZmxvYXQ+KCkgOiBUcmFpdHNCYXNlKCZUcmFpdHNCYXNlOjpmdW5jMil7fQp9OwppbnQgbWFpbigpewogICAgVHJhaXRzPGludD4gaTsKICAgIGkuY2FsbCgpOwogICAgVHJhaXRzPGZsb2F0PiBmOwogICAgZi5jYWxsKCk7CiAgICAKfQ==