Inheritance

J

Jim

Hi,
I've got a class(extendRA) which inherits from another class (regrid).
The method (regridder) which does most of the objects work is
contained in the base class, however two of the methods it uses to do
it's job are overridden in the derived class. When I instantiate the
derived class, I want to call the base classes method regridder but
have it use the new overridden methods.

I have a feeling this isn't possible, but overridding the regridder
method in derived class, which doesn't need to change , seems
inefficient.

Any ideas? The code's pretty bulky so I don't really want to post it
and it's a fairly general point. All I want is the majority of the
program to stay constant, but just change these small methods for
special cases.

Thanks!
 
A

AnonMail2005

Hi,
I've got a class(extendRA) which inherits from another class (regrid).
The method (regridder) which does most of the objects work is
contained in the base class, however two of the methods it uses to do
it's job are overridden in the derived class. When I instantiate the
derived class, I want to call the base classes method regridder but
have it use the new overridden methods.

I have a feeling this isn't possible, but overridding the regridder
method in derived class, which doesn't need to change , seems
inefficient.

Any ideas? The code's pretty bulky so I don't really want to post it
and it's a fairly general point. All I want is the majority of the
program to stay constant, but just change these small methods for
special cases.

Thanks!
This is perfectly fine and a common idiom in C++.

You should try it in sample program with some sample classes
to illustrate the idea (this way, you won't be distracted by
the bulk of your actual class).
 
A

AnonMail2005

This is perfectly fine and a common idiom in C++.

You should try it in sample program with some sample classes
to illustrate the idea (this way, you won't be distracted by
the bulk of your actual class).- Hide quoted text -

- Show quoted text -

I assumed in the above that the overriden functions are supposed
to be overriden in the derived class - that is, they are declared
virtual in the base class.
 
T

tragomaskhalos

Hi,
I've got a class(extendRA) which inherits from another class (regrid).
The method (regridder) which does most of the objects work is
contained in the base class, however two of the methods it uses to do
it's job are overridden in the derived class. When I instantiate the
derived class, I want to call the base classes method regridder but
have it use the new overridden methods.

I have a feeling this isn't possible, but overridding the regridder
method in derived class, which doesn't need to change , seems
inefficient.

Not only is this fine, it's a standard idiom:
google "template method pattern".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,104
Latest member
LesliVqm09
Top