OK, thanks. The reason I ask is because I have classes that actually look
more like this:
base class: "foo"
|------------method: connect_to_db()
|
|>>>>derived class: "bar_1"
| |------------method: init_columns()
|
|>>>>derived class: "bar_2"
| |------------method: init_columns()
The connect_to_db() method of foo is inherited by the bar_n classes. This
method just opens a database connection, and each derived class can use the
common inherited connect_to_db() method without change. The init_columns()
method of each derived class contains some code specific to the bar_n()
object, and this method can't be implemented (afaik) in "foo". I'd like to
cut down on some code and call init_columns() and some other functions that
had to be implemented in foo directly from connect_to_db(), but it's
implemented only in foo. The reason I'd like to do this is that I'm
noticing a lot of repetitive code in some of these methods, which I'd like
to eliminate.
Thanks
"SvenC" <Sv***@community.nospamwrote in message
news:OE**************@TK2MSFTNGP02.phx.gbl...
Hi Mike,
"Mike C#" <xy*@xyz.comwrote in message
news:Oq**************@TK2MSFTNGP02.phx.gbl...
>Suppose I have a base class "foo". Another class, "bar" derives from it.
Base class "foo" has a method called "rob_the_liquor_store()", and the
inherited class "bar" overrides this method with one of its own, maybe
specifying the liquor store over on 44th Street and 5th Avenue or
something.
Anyway this is what we have so far:
base class: "foo"
|------------method: "rob_the_liquor_store()"
|
|
derived class: "bar" inherits from "foo"
|------------method: "rob_the_liquor_store()"
Now the question: If I add another method to "foo" (in keeping with
character, let's call it "commit_a_felony()"), can I specify that it
should call the inherited class's ("bar's") "rob_the_liquor_store()"
method instead of the base class's? If so, how?
Technically yes, but if you are in such a situation to need this is looks
like you should reconsider your class design.
First: you have to be sure that while you are in a method of foo your
instance is at least a bar instance or further derived otherwise your bar
method can "get upset" as it executes without the proper class layout it
expects. E.g. if bar has an instance member this will only be valid if you
have a bar instance otherwise it will be random memory.
So you can but should not do this in a foo method:
((bar*)this)->commit_a_felony()
--
SvenC
>Thanks