I want to override operator+
for my classes Fridge and TV (to make it add power consumption), so I made them extend Rtv class which should override that operator, however I don't know how to get proper POWER_CONSUMPTION
field value if both Fridge and TV have different overriden value.
To be more precise i want to achieve this to be possible:
Fridge fridge = new Fridge();
Tv tv = new Tv();
int totalPowerConsumptionOfFridgeAndTv = fridge + tv;
My idea for Rtv class was:
class Rtv
{
private const int pOWER_CONSUMPTION= 0;
public static int POWER_CONSUMPTION=> pOWER_CONSUMPTION;
public static int operator+ (Rtv a, Rtv b)
{
return a.GetType().POWER_CONSUMPTION + b.POWER_CONSUMPTION;
}
}
But simply doesn't work.