A
anon
How can I do the following....
interface iface
{
int someMethod();
}
class c1 : iface
{
int someMethod() {return 10;}
}
class c2 : c1
{
int new someMethod() {return 20;}
}
class c3 : c1
{
int new someMethod() {return 30;}
}
class Test
{
int testMethod()
{
return testInterface(new c3());
}
int testInterface(iface i)
{
// in this case, returns 10
// as it stands now, i have to
// cast it to a c1, before it will
// return correct value;
return i.testMethod
}
}
If i pass in a c1, I would like to return 10, however if
I pass in a c3, I would like it to return 30. Right now,
when passing in a c3, it returns 10. This is not what I
expected, although I think i understand why this happens.
I would like to do this without have to figure out which
type was passed in... I would think that if I passed in a
c3, then c3's method would be called.. and not c1's
method.
Thanks
interface iface
{
int someMethod();
}
class c1 : iface
{
int someMethod() {return 10;}
}
class c2 : c1
{
int new someMethod() {return 20;}
}
class c3 : c1
{
int new someMethod() {return 30;}
}
class Test
{
int testMethod()
{
return testInterface(new c3());
}
int testInterface(iface i)
{
// in this case, returns 10
// as it stands now, i have to
// cast it to a c1, before it will
// return correct value;
return i.testMethod
}
}
If i pass in a c1, I would like to return 10, however if
I pass in a c3, I would like it to return 30. Right now,
when passing in a c3, it returns 10. This is not what I
expected, although I think i understand why this happens.
I would like to do this without have to figure out which
type was passed in... I would think that if I passed in a
c3, then c3's method would be called.. and not c1's
method.
Thanks