Re: Help with the, "this" initializer in a constructor.

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

From: Player (guess_at_My.email.address.scum.com)
Date: 11/01/04


Date: Mon, 1 Nov 2004 17:04:43 -0000


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Yeah great thanks Nick Malik..

I went through what you said, read some more then experimented a little..

I came out of it with the following code...

class A
{
      public A()
      {
            myMethod();
       }

       public virtual void stuff()
       {
            Console.WrteLine("A");
        }
} // end class A

class B : A
{
     public B() : base()
     {
     }

     public override void myMethod()
     {
         Console.WriteLine("B");
     }
} // end class B

Which DOES end up giving me the desired output, "B".

And I now understand why it's done like that, and why the base constructor
is always called, explicitly or not; But how you can override such
constructors and/or methods in order to achieve the desired goal :)

In the case above, it's still calling the base constructor, which is calling
the, "myMethod()" method, it's just that I am explicitly calling the base
constructor in my derived class, AND overriding the, "myMethod" in the
derived class, to get the desired result.

Thanks again to all - appreciated :)

Player

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBQYZsqS/z2sM4qf2WEQKBWgCfeUehgq3hJIMpe69DDwQDEguCPh8AnR/A
813v8OmJFUknYyR5uYp6EMxL
=7q0b
-----END PGP SIGNATURE-----



Relevant Pages

  • Re: Preventing type extensions
    ... operation separately for each derived class. ... he would avoid the redispatching by ... overriding the calling operation for each derived class, ... I am trying not to override non-abstract or non-null operations. ...
    (comp.lang.ada)
  • Re: Cant use TComponent in thread object?
    ... you are calling the base constructor, which takes a boolean. ... it fail when I pass it the correct parameter? ... you need to include the name of the method you're calling: ...
    (alt.comp.lang.borland-delphi)
  • Re: Type Load failure in Web Service Client
    ... >> System.Web.Services.Protocols.Soap HttpClientProtocol ... > calling a connection that fails. ... If the base constructor is checking for something, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: :: Scope qualifier misunderstanding.
    ... > arguments from the derived constructor). ... > I was hoping this would set the values in the derived class using the ... > base constructor. ... and how to remedy this? ...
    (comp.lang.cpp)
  • Re: Cant use TComponent in thread object?
    ... procedure UpdateProgress; ... I get an incompatible types error on the inheritied line. ... you are calling the base constructor, ...
    (alt.comp.lang.borland-delphi)