cplusplus forum
I have several inherited classes from a base class. I added a function to the
base class but don't want the inherited classes to each have a copy of this
function.
Is there a way to isolate this function to the base class only with "private"
or the "new" modifier so the inherited classes don't reserve memory for it.
What do you mean by "memory"? Functions aren't copied. The size of an object wouldn't increase by adding a function (unless it's the first virtual function, which necessitates a v-table pointer).
Yes, making a function private will prevent subclasses from accessing it. Any restriction beyond this will be counter-productive or an exercise in obfuscation.
What is the real problem that you're trying to solve?
Ganado,
I just didn't want to add a function to the base and have it repeated in all
the inherited classes but you've stated that methods aren't be so that's
answers my question.