473,767 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to call a base class of a base class

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:

ChildCheckBoxLi st : CheckBoxList

this class has a method

protected override void CreateChildCont rols()

which calls the base method (e.g. CheckBoxList.Cr eateChildContro ls):

base.CreateChil dControls();

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

OwnChildCheckBo xList : CheckBoxList

where I want to override the CreateChildCont rols()
but there I want to call the CreateChildCont rols() method of
CheckBoxList and _not_ of ChildCheckBoxLi st.

How can I do this?

base.base.Creat eChildControls( );

does not work.
Regards,

Martin
Nov 19 '08 #1
5 2300
Hi Martin,

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

((CheckBoxList) this).CreateChi ldControls();
Walter
Nov 19 '08 #2
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
AJ
.... and not even then, if it's a virtual function!
In article <13************ *************** *******@microso ft.com>,
cs*******@web.d e 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
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
>>
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
5183
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
9
3676
by: Daniel Kay | last post by:
Hello! I have written two template classes which implement the observerpattern in C++. I hope I manage to desribe the problem I have. template<class T> class Observer { /* ... */ }; template<class T> classSubject {
9
11576
by: keith | last post by:
I created a class libery which has name space Assembly and class Assembly and compiled it. Then created a C# project and called a method in the external class e.g. Assembly dll; dll=Assembly.LoadFrom(@"c:\app\Assembly.dll");
15
12790
by: jon | last post by:
How can I call a base interface method? class ThirdPartyClass :IDisposable { //I can not modify this class void IDisposable.Dispose() { Console.WriteLine( "ThirdPartyClass Dispose" ); } } class MyClass :ThirdPartyClass, IDisposable { void IDisposable.Dispose() {
3
1535
by: John A. Prejean | last post by:
This one has me stumped. I have a base form I am trying to wrap up, but I have one problem. In two functions I am opening a "record detail" form. I would like to keep the code in the base form and pass info to the form telling it which from to actually open. Any ideas how to do this? Here is an example of what I had in mind if the text isn't clear enough... Base Form Function EditRecord() Dim frmRecord as New Form()
6
2499
by: Taran | last post by:
Hi All, I tried something with the C++ I know and some things just seem strange. consider: #include <iostream> using namespace std;
1
1879
by: mwebel | last post by:
Hi ikind of remember this being easy but cant find it on google: i have a base class and a derived class. The base class has two constructors normal and int overloaded one. thing is i want the derived class to call the constructors for the base class using also the same kind of overloading. like this: class BASE{ public: BASE(); BASE(int x);
1
1474
by: Martijn Mulder | last post by:
Documentation suggests that I should make a call to the base-class method for some methods. When I try to do so for the class below, I get wrong results. What is the correct way to make a call to the base class for an event like this? //class Form class Form:System.Windows.Forms.Form {
4
14420
by: Javier | last post by:
Hello, is this possible? I have a pure virtual function in the base class (to force the programmers of the derived classes to have this function implemented) but I want to call the derived class function from a base class reference: class A { public: virtual void function() = 0;
4
1089
by: The Doctor | last post by:
I have a question about virtual functions, and all that stuff. Let's say, I have three classes. class Base; class firstDerived; class secondDerived; I defined them as following:
0
9405
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9841
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7383
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5424
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3930
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3533
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2807
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.