I have been using a template with an enum argument to provide specialised methods for output from my code.
template <Device::devEnum d>
struct sensorOutput;
template<>
struct sensorOutput <Device::DEVICE1>
{
void setData(Objects& objs)
{
// output specific to DEVICE1
// output velocity
objs.set(VELOCITY, vel[Device::DEVICE1]);
// output position
objs.set(POSITION, pos[Device::DEVICE1]);
}
};
template <>
struct sensorOutput <Device::DEVICE2>
{
void setData()
{
// output specific to DEVICE2
// output altitude
objs.set(ALTITUDE, alt[Device::DEVICE2]);
}
};
I now want add another sensor similar to DEVICE1 that will output velocity and position.
Is there a way of setting multiple specialisations? I have tried
template <>
struct sensorOutput <Device::DEVICE1 d>
struct sensorOutput <Device::DEVICE3 d>
{
void setData()
{
// output specific to DEVICE1 and DEVICE3
// output velocity
objs.set(VELOCITY, vel[d]);
// output position
objs.set(POSITION, pos[d]);
}
};
How about inheritance?