By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

How to call a base class of a base class

P: n/a
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
Nov 19 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Martin,

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

((CheckBoxList)this).CreateChildControls();
Walter
Nov 19 '08 #2

P: n/a
Hi Martin,

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

regards
Walter
Nov 19 '08 #3

P: n/a
AJ
.... and not even then, if it's a virtual function!
In article <13**********************************@microsoft.co m>,
cs*******@web.de says...
Hi Martin,

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

regards
Walter
Nov 19 '08 #4

P: n/a
sorry for my post. This does not work with protected Members.
Only if the function you are calling is public.
On 19 Nov., 14:38, AJ <no...@nowhere.comwrote:
... 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
Nov 19 '08 #5

P: n/a
>>
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.

--
Pete
====
http://mrpmorris.blogspot.com
http://www.capableobjects.com

Nov 19 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.