(I did scan, but couldn’t find anything similiar, if dupe please close).
Is there a way to prevent these two operators from being inherited? For example:
struct foo{
static void* operator new(std::size_t) {
// special
}
static void operator delete(void* p, std::size_t) {
// special
}
};
struct bar : public foo {
};
Now bar will inherit the two operators – in this trivial case, not such a big deal, problem arises if there are data members in foo and bar (and worse in my case, as allocation for foo needs to be done differently to bar!) Now the way to avoid this is that in bar, I would implement the operators too. However if there are lots of derived types, the likelyhood of forgetting to override somewhere is quite possible. So question is, is there a way to prevent these operators from being inherited?
NOTE: c++03 (and willing to accept some compiler specific solution if it’s specific to gcc)
You could define an intermediate foo which calls global new/delete again and derive from that.
There is some more work involved if you have to forward constructors of course.