No, the "base" of any class must be a class or struct.
Assuming you actually want to alter the behaviour (e.g. check for over-/underflow in operators +
, -
, *
- I don't think divide is particular bothersome for this particular problem). This means that you have to implement the operators +
, -
and *
, =
, +=
, -=
, *=
, ++
and --
).
Which you could do by:
template<class T> OverflowDetector
{
private:
T member;
public:
T& operator+(T) { ... };
T& operator-(T) { ... };
explicit T operator T () { return member; }
};
Then use like:
typedef OverflowDetector<int> safe_int;
safe_int si1, si2;
si1 = 7;
si2 = 18;
int x = int(si2);
(Yes, you probably need to have some traits type things and a lot more sophistication to stop people doing OverflowDetector<double>
or something like that)
You volatile-lockfree class sounds suspiciously similar to std::atomic<T>
- I'm sure you had some other ideas, but still, I'm not sure I see the point in inheriting over just implementing using templates...