473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

changing parameter types on inherited member

Could someone tell me how to Change the parameter type for an override of an
inherited class member? In particular, I would like to change an indexer for
my class that implements the IList class. Such as this:

public abstract class myclass : IList
{
private ArrayList ary;

....[Cut for brevity]
public string this[int index]
{
get
{
return (string)this.ary[index];
}
}
....[Cut for brevity]
}

When I try to compile, I get (my class) "does not implement interface member
'System.Collections.IList.this[int]'." etc..

It appears I am being required to use a type of object instead of string.
I would prefer not to have to cast to string upon every call to this indexer
from other classes.

Any help would be appreciated.

Jan 8 '06 #1
2 2129
Hi Walt,

implementing IList requires you to provide a method with the exact signature
as declared in the interface, in this case "Object this[Int32] {get;set;}".
If you change the returntype, you're no longer implementing the interface.

There's a simple way to do want you want: leave your indexer, but add the
following (untested):
Object IList.this[Int32 index]
{
get
{
return this[index];
}
set
{
...
}
}

You'll find more info by googling on "explicit interface implementation";

hth, Baileys

"Walt Zydhek" wrote:
Could someone tell me how to Change the parameter type for an override of an
inherited class member? In particular, I would like to change an indexer for
my class that implements the IList class. Such as this:

public abstract class myclass : IList
{
private ArrayList ary;

...[Cut for brevity]
public string this[int index]
{
get
{
return (string)this.ary[index];
}
}
...[Cut for brevity]
}

When I try to compile, I get (my class) "does not implement interface member
'System.Collections.IList.this[int]'." etc..

It appears I am being required to use a type of object instead of string.
I would prefer not to have to cast to string upon every call to this indexer
from other classes.

Any help would be appreciated.

Jan 8 '06 #2
Your suggestion of adding the explicit inherited member without the public
keyword, and including the base class name in the method name resolved my
issue. Thank you very much!

"Baileys" wrote:
Hi Walt,

implementing IList requires you to provide a method with the exact signature
as declared in the interface, in this case "Object this[Int32] {get;set;}".
If you change the returntype, you're no longer implementing the interface.

There's a simple way to do want you want: leave your indexer, but add the
following (untested):
Object IList.this[Int32 index]
{
get
{
return this[index];
}
set
{
...
}
}

You'll find more info by googling on "explicit interface implementation";

hth, Baileys

"Walt Zydhek" wrote:
Could someone tell me how to Change the parameter type for an override of an
inherited class member? In particular, I would like to change an indexer for
my class that implements the IList class. Such as this:

public abstract class myclass : IList
{
private ArrayList ary;

...[Cut for brevity]
public string this[int index]
{
get
{
return (string)this.ary[index];
}
}
...[Cut for brevity]
}

When I try to compile, I get (my class) "does not implement interface member
'System.Collections.IList.this[int]'." etc..

It appears I am being required to use a type of object instead of string.
I would prefer not to have to cast to string upon every call to this indexer
from other classes.

Any help would be appreciated.

Jan 8 '06 #3

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

Similar topics

3
by: Dave | last post by:
Hello all, Quoting from page 24 of "The Boost Graph Library; User Guide and Reference Manual": "It turns out that by the contravariance subtyping rule, the parameter type in the derived...
1
by: Dave | last post by:
Hello NG, Regarding access-declarations and member using-declarations as used to change the access level of an inherited base member... Two things need to be considered when determining an...
9
by: Ryan Taylor | last post by:
Hello. I am trying to overload a method so that I have four possible working copies. The only difference between the four methods is what to search by and in what manner to return the results....
3
by: Wayne Brantley | last post by:
VS2005 RTM Create a web user control to use as a base class for other web user controls. Now, create a new web user control, change the class it inherits from to your base class and compile....
13
by: dragoncoder | last post by:
Consider the following code #include <iostream> class Base { public: virtual void say() { std::cout << "Base" << std::endl; } }; class Derived: public base {
6
by: GarrettD78 | last post by:
Accidently posted this to the wrong group so I am reposting. This is probably a newbie question but I am a little confused about how to go next with my code. I think I want to use a factory pattern...
3
by: kikazaru | last post by:
Is it possible to return covariant types for virtual methods inherited from a base class using virtual inheritance? I've constructed an example below, which has the following structure: Shape...
1
by: interX | last post by:
Hi I'm new in VC++ and have a question to generics. I have a generic class, which contains an array of the generic type. This array I can pin and then I would like to get an unmanaged pointer to...
5
by: alan | last post by:
Hello world, I'm wondering if it's possible to implement some sort of class/object that can perform mapping from class types to strings? I will know the class type at compile time, like so:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.