template <typename T>
class AutoCalcNumber {
public:
T& val;
AutoCalcNumber(T& x) : val(x) {}
operator T() const {
return val + 10;
};
};
long x;
AutoCalcNumber<long> y(x);
void setup() {
Serial.begin(115200);
x = 10;
Serial.println(y); // will print 20
x = 20;
Serial.println(y); // will print 30
long z = y * 2;
Serial.println(z); // will print 60 but z won't evolve when x evolves. One time evaluation
}
void loop() {}