I want to permanently set one variable to be the sum of two other integer variables in c++, such that the value of the sum variable will change as either or both of the original two variables change:
#include <iostream>
int main()
{
int myInt = 3;
int myInt2 = 5;
int mySum = myInt + myInt2; // Something here so that mySum changes with myInt and myInt2
std::cout << mySum << std::endl; // Should output 8
myInt = 10;
std::cout << mySum << std::endl; // Should output 15
myInt2 = 30;
std::cout << mySum; // Should output 40
}
Is this possible to do, whether with references/pointers or some other method?