Re: Overriding newbie question.

From: Richard Blewett [DevelopMentor] (richardb_at_NOSPAMdevelop.com)
Date: 12/05/04


To: microsoft.public.dotnet.languages.csharp
Date: Sun, 05 Dec 2004 03:41:04 -0800

The base and derived class method signatures for method B must match exactly so:

 class Foo
 {
    public virtual int MyMethod(double d)
    {
    }
 }

 class Bar : Foo
 {
   public override int MyMethod(double d)
   {
     // this one will not always get called
   }
 }

 The other fundemental thing is this will only work if the method is being called on a derived class object. So for the above example:

 Foo f = new Foo();
 f.MyMethod(2.0); // this will call Foo.MyMethod

 f = new Bar();
 f.MyMethod(2.0); // this will call Bar.MyMethod

 Regards

 Richard Blewett - DevelopMentor
 http://www.dotnetconsult.co.uk/weblog
 http://www.dotnetconsult.co.uk

   Hi,
 A control has
 privtae void MethodA()
 {
 
 //etc
 
 MethodB();
 {
 
 // NO CODE, THE PROGRAM WHICH WILL INHERIT THIS CONTROL WILL PROVIDE THE CODE.
 }
 
 I hope this make sense, I have tried using virtual and override without success the control always calls its own methodB
 
 any help/thoughts will be appericated.
 



Relevant Pages

  • Re: derived class can not access base class protected member?
    ... I am not invoking foo in derived class, the error occurs when I invoke ... void goo() ... Because foois defined as PRIVATE in the base class ...
    (microsoft.public.dotnet.languages.vc)
  • Re: [CLOS] Ensuring a method exists
    ... (defgeneric foo (a b) ... (defclass base () ... I'd like to ensure that if somebody writes a derived class: ... to define the foo method? ...
    (comp.lang.lisp)
  • Re: Function Returning a local object???
    ... >>are themselves class objects or worse still objectsof a derived class, ... >>when foo returns such a class by value. ... the compiler will emit code similar to: ... >>(I've read enough to know that the copy constructor is only invloved ...
    (comp.lang.cpp)
  • Re: Function Returning a local object???
    ... because I can imagine the return value of foo() ... > derived class class whose member variables are themselves class ... > objects or worse still objectsof a derived class, ... the constructor, destructor and copy constructor if you don't defined ...
    (comp.lang.cpp)
  • Re: NOOB QUESTION: How can I access an element in nested classes
    ... function ChangeA() does not work because 'a' doesn't belong to Bar; ... belongs to Foo. ... class Bar change an element that belongs to Foo? ... public void DoSomethingWithBar() ...
    (microsoft.public.dotnet.languages.csharp)