I would like to be able to provide to the base class MCFormater a formatting method that would work for different types (uint32, uint8...)
class MCFormater {
public:
MCFormater() {}
virtual ~MCFormater() {}
virtual mcc_t Gen();
protected:
template<typename K> //here is the problem
virtual void Format(K& a, const K& b) = 0;
//...
uint32_t a;
uint8_t b;
void Foo();
};
void MCFormater::Foo() {
Format<uint32_t>(a, 3); //I want to be able to call for Format
Format<uint8_t>(b, 3); //with uint32_t, and uint8_t, and more
}
class GFormater : public MCFormater {
GFormater() {}
template<typename K>
virtual void Format(K& a, const K& b) {
a = b;
}
};
class EFormater : public MCFormater {
EFormater() {}
template<typename K>
virtual void Format(K& a, const K& b) {
a |= b;
}
};
but I get the error: templates may not be 'virtual'. what is the right way to do it? (is there one?)