473,832 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Base keyword - HELP

Hi,
Am having a base class that implements an interface (air code) :

class BaseClass : SomeInterface
{
void SomeInterface.I mplMethod()
{
// -- code here --
}
}

class Derived : SomeInterface
{
void SomeInterface.I mplMethod()
{
//NEED TO CALL BASE'S IMPLEMENTATION HERE
// -- code here --
}
}

Without making the implementations public, is there a way to do it?

TIA
Krishnan
Nov 17 '05
17 2062
Wait, so Dervied DOES or does NOT derive from class Base?

If it does, just use:

base.ImplMethod ();

--
Adam Clauss

"Krishnan" <kr************ *********@myrea lbox.com> wrote in message
news:OR******** ********@TK2MSF TNGP15.phx.gbl. ..
Thanks for the reply. I missed out on mentioning the base class
inheritance in the derived class.
"Wessel Troost" <no****@like.th e.sun> wrote in message
news:op.styc180 rxgtv7i@asbel.. .
class BaseClass : SomeInterface
class Derived : SomeInterface


The derived class doesn't inherit from the base class?

However, even when inheriting, I couldn't find a way to call the base
class interface function. Maybe someone else knows how to do it?

I only found this work-around, by moving the code to a helper function.
Like this:

interface SomeInterface
{
void ImplMethod();
}

class BaseClass : SomeInterface
{
protected void Method() { /* Code goes here */ }
void SomeInterface.I mplMethod() { Method() }
}

class Derived : BaseClass, SomeInterface
{
void SomeInterface.I mplMethod() { base.Method(); }
}

Greetings,
Wessel


Nov 17 '05 #11
> Wait, so Dervied DOES or does NOT derive from class Base?
If it does, just use:

base.ImplMethod ();

For some reason, that doesn't work if ImplMethod is an interface method.

Greetings,
Wessel
Nov 17 '05 #12
The following works just fine, just tried it (note - if Derived derives from
BaseClass, as mine does then ImplMethod must either be marked as new in
Derived, or virtual in base/override in Derived.):

public interface SomeInterface
{
void ImplMethod();
}
public class BaseClass : SomeInterface
{
public void ImplMethod()
{
Console.WriteLi ne("BaseClass.I mplMethod");
}
}
public class Derived : BaseClass
{
public new void ImplMethod()
{
base.ImplMethod ();
Console.WriteLi ne("Derived.Bas eClass");
}
}

--
Adam Clauss

"Wessel Troost" <no****@like.th e.sun> wrote in message
news:op.styi8yi ixgtv7i@asbel.. .
Wait, so Dervied DOES or does NOT derive from class Base?
If it does, just use:

base.ImplMethod ();

For some reason, that doesn't work if ImplMethod is an interface method.

Greetings,
Wessel

Nov 17 '05 #13
"Adam Clauss" <ca*****@tamu.e du> schrieb im Newsbeitrag
news:11******** *****@corp.supe rnews.com...
The following works just fine, just tried it (note - if Derived derives
from BaseClass, as mine does then ImplMethod must either be marked as new
in Derived, or virtual in base/override in Derived.):

public interface SomeInterface
{
void ImplMethod();
}
public class BaseClass : SomeInterface
{
public void ImplMethod()
{
Console.WriteLi ne("BaseClass.I mplMethod");
}
}
public class Derived : BaseClass
{
public new void ImplMethod()
{
base.ImplMethod ();
Console.WriteLi ne("Derived.Bas eClass");
}
}

--
Adam Clauss


Yes, but that's implicit member implementation and the memeber is public.
The OP said it shall not be public, so he has to use explicit member
implementation.

Christof
Nov 17 '05 #14
> ImplMethod must either be marked as new in Derived, or virtual in
base/override in Derived.


Thanks, that was the information I was missing.

Greetings,
Wessel
Nov 17 '05 #15
Oh yes. You are right. I tried a similar workaround with the method marked
virtual and had a confusion. This should work fine (and actually, so should
my case ;) ).

Thanks a ton.

Krishnan

"Christof Nordiek" <cn@nospam.de > wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..

"Krishnan" <kr************ *********@myrea lbox.com> schrieb im Newsbeitrag
news:eM******** ******@tk2msftn gp13.phx.gbl...
Just one Q. The line,
void SomeInterface.I mplMethod() { Method() }

would call the most derived version's method, right? I mean there is no
"MyClass" keyword in C# :(

Why this would be a problem?
In the code of Wessel Troost BaseClass.Metho d is not virtual, so there
never will be a more derived version.

Christof

Nov 17 '05 #16
"Christof Nordiek" <cn@nospam.de > wrote in message
news:uf******** ******@TK2MSFTN GP12.phx.gbl...
Yes, but that's implicit member implementation and the memeber is public.
The OP said it shall not be public, so he has to use explicit member
implementation.


Huh? It's an interface method. It MUST be public. There is no other kind.

--
Adam Clauss
Nov 17 '05 #17
Adam Clauss <ca*****@tamu.e du> wrote:
"Christof Nordiek" <cn@nospam.de > wrote in message
news:uf******** ******@TK2MSFTN GP12.phx.gbl...
Yes, but that's implicit member implementation and the memeber is public.
The OP said it shall not be public, so he has to use explicit member
implementation.


Huh? It's an interface method. It MUST be public. There is no other kind.


No - if you use explicit interface implementation you end up with a
method which is sort of public and sort of private.

From the language spec:

<quote>
Explicit interface member implementations have different accessibility
characteristics than other members. Because explicit interface member
implementations are never accessible through their fully qualified name
in a method invocation or a property access, they are in a sense
private. However, since they can be accessed through an interface
instance, they are in a sense also public.
</quote>

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2288
by: Jacek Generowicz | last post by:
Where can I find concise, clear documentation describing what one has to do in order to enable Python's internal help to be able to provide descriptions of Python keywords ? I am in a situation where I have to give Python novices the ability to fix this for themselves easily. Failing "concise" and "clear", how about "complete and correct" ?
1
2968
by: Bob Rock | last post by:
Hello, I have read that the base keyword can be used not only to control a base class instantiation (thus calling one of the base class constructors) but also to access any other public or protected method in the parent class ... I have search all over for an example of how to do this but have failed. What I was wondering is about the syntax necessary to make such a call ..... Thx.. Bob Rock
7
1153
by: Rob Meade | last post by:
Hi all, Ok - I'm going around in circles and would appreciate some help. I have written a windows service, which up until I tried to be clever was working well :o) I have a main class which inherits a base class, I also have a "configuration" class which stores a load of values read in from an xml file which I would like to be available at any time (without reading the xml file
5
1121
by: BartlebyScrivener | last post by:
Using ActivePython 2.4.3 on Windows XP While in the Pythonwin IDE, if I seek keyword help by issuing the following command: >>>help ('while') I get: Sorry, topic and keyword documentation is not available because the
11
2713
by: jyck91 | last post by:
// Base Conversion // Aim: This program is to convert an inputted number // from base M into base N. Display the converted // number in base N. #include <stdio.h> #include <stdlib.h> #include <string.h> #define LENGTH 20 int temp, m, n, i, r, base10, true;
0
9794
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
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
10780
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...
1
10539
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10212
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...
0
5788
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4420
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
3968
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3077
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.