I have a base class, with 2 static const members - the second one being a constexpr of the first one:
constexpr int square(int n)
{
return n * n;
}
class BaseClass
{
public:
static const int original = 5;
static const int squared = square(original);
};
Which works perfectly. but I also want to create a subclass that changes only "original", and gets the changed "squared" "for free".
class SubClass : public BaseClass
{
public:
static const int original = 3;
// squared should be 9, not 25
};
Is there any way of doing this, or something similar?