Talk:More C++ Idioms/Requiring or Prohibiting Heap-based Objects

Very good! Here's a challenge for an addition:

Your solution to prevent heap allocation works for all derived classes as well. Unfortunately your solution to FORCE heap allocation does not. In fact it prevents derivation (if the destructor is private) or simply does not enforce heap allocation for derived classes (if the destructor is protected).

My challenge is to come up with a scheme that forces all DERIVED classes of a class A to be allocated on the heap (or more precisely with a custom made placement new operator) without putting any further requirements on those classes. (I.e. don't require THEIR destructors or constructors to be private or whatever)

I could only come up with a run-time test (where the base class checks that it's actual memory is within the pool that it's specific placement new uses).