Re: C# inheritance broken?



On 2007-01-27, Bruce Wood <brucewood@xxxxxxxxxx> wrote:
A generalized method of converting a base class into a derived class with
the knowledge that the derived class may still require some initialization
would definitely be useful, even if you had to do it via a constructor that
takes an object of the base class as it's argument. The missing syntax, in
vb is

mybase = objBaseClass

In C# I think it would be

base = objBaseClass

In either case, since this is occurring in a constructor in place of the
base.New() or mybase.New statement, the programmer knows he still has to
instantiate and initialize all other private and protected objects in the
derived class.

Mike Ober.

Agreed. That would be nice. I wouldn't need it often, but it would get
one out of some tricky corners. My only point was that the whole "I
have a base class instance and I want to treat it as though it were a
derived class instance" is completely unsafe and therefore runs
against the grain of what .NET is supposed to be all about. Being able
to copy state, though, would be handy.


Reflection :)

--
Tom Shelton
.



Relevant Pages

  • Re: getting used to Java - question about "style"
    ... > I am reading a book that a collegue gave me called "The Elements of Java ... > before executing the derived class constructors. ... > constructor." ... void print() { ...
    (comp.lang.java.programmer)
  • :: Scope qualifier misunderstanding.
    ... arguments from the derived constructor). ... I was hoping this would set the values in the derived class using the ... (inherits base2). ... // Base 2 declaration, ...
    (comp.lang.cpp)
  • Re: templates and inheritance
    ... I have learned the derived class does not automatically inherit the ... > base class constructors, and attempts to create new functions to work on ... Since the derived class constructor are ... > Did I miss something when I did my inheritance? ...
    (alt.comp.lang.learn.c-cpp)
  • Re: What replace "this" in static class?
    ... Originally, your class, as a derived class of QuickFix.Application, ... > function to do the constructor job. ... > This class inherit from a QuickFix.Application class. ... > And previously I was using "this" keyword because the class inherit ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: static constructor in derived class not being called
    ... Before the call to MyDerived.DoSomething, the CLR loads MyDerived and ... constructor. ... > I have the following base class and derived class. ... > public class MyBase ...
    (microsoft.public.dotnet.languages.csharp)

Loading