tomtom tomtom - 1 year ago 84
C++ Question

partial function template specialization

Hi I think I'm missing something with this technique. Tried to follow examples but the following gives me an error:

invalid use of incomplete type ‘class Citizen<T, minAge, maxAge, true>’

template <typename T, T minAge, T maxAge, bool isarmed>
class Citizen {

Citizen(T health, T age);
Citizen(T health, T age, T attackPower);
T getAttackPower();

T _health;
T _age;
T _attackPower;

template <typename T, T minAge, T maxAge>
T Citizen<T, minAge, maxAge, true>::getAttackPower() {
return _attackPower;

Answer Source

You cannot use partial template specialization for a single member function - need to specialize the entire class instead (however, full template specialization would be okay).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download