Skip to main content
2 of 3
added 867 characters in body
Rubens
  • 14.8k
  • 11
  • 68
  • 94

Make inherited members static

I have to classes, A and B, and B inherits members from A publicly.

class A { public: int a; }; class B : A { }; 

Is there a way to make all of the inherited members from A static under B, or creating them static in A is the only way through?

Context:

I'm building a memory manager, and this manager would control the memory used by instances of a particular class.

I'd have something like:

template <class T> class Memory { public: operator new; operator delete; private: memory_pool_for<T>; }; class Data : Memory<Data> { }; 

And so, when I got to do something like:

new Data; delete Data; 

The operation would be called from the function defined in Memory, that would allocate/deallocate some memory space.

The allocation/deallocation should be static among Data instances, and I'd like to be sure no extra bytes would be added to each instance of Data due to the inheritance from Memory. That's why I thought of static'lizing the inheritance.

I'm not sure if this is the best way to do what I'm doing, but this is quite the most elegant approach I could think of so far.

Rubens
  • 14.8k
  • 11
  • 68
  • 94