Re: How to call the subclass's method?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: William Stacey [MVP] (staceywREMOVE_at_mvps.org)
Date: 04/21/04


Date: Wed, 21 Apr 2004 16:49:14 -0400

If the method is unique to the subclass you may not want it virtual as other
subclasses may not need it. Have you tried to cast the object to the
subclass type like this:

mySubclass msc = (mySubclass)mc;
msc.methodOfSubclass();

-- 
William Stacey, MVP
"Quentin Huo" <q.huo@manyworlds.com> wrote in message
news:uCK7v#9JEHA.3436@tk2msftngp13.phx.gbl...
> Hi,
>
> I created a class "myClass" and another class "mySubclass" which inherited
> from "myClass". In the "mySubclass", there is a public method named
> "methodOfSubclass(...)" which is not defined in "myClass".
>
> In a client program I tried to call the "methodOfSubclass(...)", like
>
> ......
> myClass mc;
> mc = new mySubclass();
> mc.methodOfSubclass(...);
> ......
>
> but I got an error message when I tried to compile it:
>
> '...myClass' does not contain a definition for 'methodOfSubclass'
>
> What is the problem? Do I have to create a virtual method
> "methodOfSubclass(...)" in "myClass" and override it in "mwSubclass"? Any
> other solutions?
>
> Thanks
>
> Q.
>
>
>


Relevant Pages

  • Re: How to call the subclasss method?
    ... if(mc is mySubclass) ... > myClass mc; ... > but I got an error message when I tried to compile it: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Understanding class access
    ... MySubClass invisible for packages outside mycompany.mypackage? ... side note, if MySubClass is a subclass of MyClass, then trying to access ... MySubClass from MyClass is a cyclic dependency anyway.) ... anyone outside of mycompany.mypackage to access MySubClass. ...
    (comp.lang.java.programmer)
  • Re: How to declare a sub class
    ... then change the subclass to be defined with the Friend scope. ... Public Class MyClass ... Friend Class MySubClass ... Private Class MySubClass ...
    (microsoft.public.dotnet.languages.vb)
  • Re: ClassName.attribute vs self.__class__.attribute
    ... but MyClass and Superclass do not because they're already ... Going further, self.a retrieves the instance attribute if it exists, ... these methods return path objects rather than your subclass ...
    (comp.lang.python)
  • Re: How to declare a sub class
    ... public declare _AVariable as string ... Public MySubClass as new SubClass ...
    (microsoft.public.dotnet.languages.vb)