I have following abstract class in C++
class Converter
{
public:
virtual void enable(void) = 0;
virtual void setReferenceValue(double) = 0;
virtual void registerAlarmListener(AlarmListener*) = 0;
virtual void confirmAlarm() = 0;
virtual void notifyParameterChange() = 0;
virtual void update(void) = 0;
}
My intention was that this abstract class will be a common interface for all
kinds of power electronics converters in my application. Unfortunatelly I have
hit a problem how to model a situation when all kinds of power electronics
converters has a set of parameters and a set of alarms but the items of those
sets depend on each type of the converter. So I don't know how to fully declare
the methods confirmAlarm
and notifyParameterChange
because I don't know how to
declare type of the formal parameters. I would probably need to define some type
which will model a common list of parameters and common list of alarms. Can anybody
give me an advice how to do that? Thanks in advance for any ideas.
You can do that with polymorphism: define BaseParam
and BaseAlarm
classes and use vector
s of pointers to them as an argument to your functions.
Alternatively, you can use vector
of std::variant