How to call a base class of a base class

M

macap.usenet

Hello,

I´ve a problem which maybe sounds a bit easy, but it is hard do ask
google for the problem.

I have a CheckBoxList and a class derived from this checkboxlist

Let´s say:

ChildCheckBoxList : CheckBoxList

this class has a method

protected override void CreateChildControls()

which calls the base method (e.g. CheckBoxList.CreateChildControls):

base.CreateChildControls();

now I want to make my own CheckBoxList class derived from
ChildCheckBoxList:

OwnChildCheckBoxList : CheckBoxList

where I want to override the CreateChildControls()
but there I want to call the CreateChildControls() method of
CheckBoxList and _not_ of ChildCheckBoxList.

How can I do this?

base.base.CreateChildControls();

does not work.


Regards,

Martin
 
W

Walter Frank

Hi Martin,

just cast your object to the desired type and then call the function:

((CheckBoxList)this).CreateChildControls();


Walter
 
W

Walter Frank

Hi Martin,

sorry for my post. This does not work with protected Members.
Only if the function you are calling is public.

regards
Walter
 
M

macap.usenet

... and not even then, if it's a virtual function!

Hi all,

thanks for your answers. I found out that I do not need it, because it
´s not necessary to call the base-method to solve my problem.

But all in all...

Is there no way to call a base class of a base class?


As simple example...

What for example if I have a class "Bike" and a class "Motorbike" and
I want to create a class
"HondaMotorbike" which should derive everything from "Motorbike"
except a method "drive()" because
I want to drive my HondaMotorbike like a normal Bike (Bicycle)?

I know it´s a stupid example but I think it´s clear what my general
question is.
So how can I do that in C#?


Regards,

Martin
 
P

Peter Morris

I know it´s a stupid example but I think it´s clear what my general
question is.
So how can I do that in C#?
<<

You can't, and you shouldn't be able to in any decent OOP. What happens if
later you introduce another class FuelledBike between Bicycle and Motorcyle?
Your could wouldn't behave as expected. You explicitly define which class
you are extending, and which methods you are going to override, with the
ability to call the base method at any point you wish. You should not care
HOW the base class implements its functionality (whether inherited,
overridden, etc), just what it does.
 

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

Top