Re: Selective Inheritance?
Suraj <surajprakash.25@gmail.com> wrote:
I have a base class (Base) with a lot of member variables. The size of
this class is 16bytes.
I need to implement another class (Derived) with partially different
functionality. If I derive Derived from Base, all members of Base
would be available in Derived.
This is unnecessary. In fact, the actual members that are needed just
constitute of 8bytes of data.
I need to develop a mechanism to selectively inherit member variables
and functions from Base into Derived.
Note that any change in Base isn't possible.
1. Is it possible?
2. How?
No it is not possible, but are you sure it is necessary? The only reason
you *must* derive your new class from Base is if you actually have to
substitute members of the second class where members of the first class
are expected (either via pointer or reference.)
If you *must* substitute a member of some other class for a Base object
and the only way to do that is to subclass from Base, then the library
you are working with was written poorly and now you have to pay for that.