Re: base, derived objects

Chad Yost <[email protected]> Fri, 4 May 2007 07:26:44 -0500
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <003c01c78e47$7ae13430$bf6dfea9@chad>
Is the base class not under your control?

If it is, just change the base to take it's own type (i.e. a copy
constructor), and have that one copy all the members itself.  Because
scoping is handled by the compiler (not the runtime) a constructor in Base
can sell all the private members of the passed in Base constructor - you
don't need to make anything internal or public.

For example:

class Base {
    ... Other Constructors here ...
    public Base(Base b) {
        this.member1 = b.member1;
        this.member2 = b.member2;
        ... others ...
    }
}

class Derived {
   public Derived (Base b) : base(b) {
      ... other stuff here ...
   }
}

Chad

-----Original Message-----
From: Discussion relating to the specifics of the C# and Managed C++
languages [mailto:[email protected]] On Behalf Of Chris Anderson
Sent: Thursday, May 03, 2007 4:53 PM
To: [email protected]
Subject: Re: [DOTNET-CX] base, derived objects

> I don't follow you here...
>
> >> You could code the ctor to take a object of type Base, but how
would
> you extract the private members >> from it without exposing them to
> other classes.
>
> How does this affect other classes.  Perhaps if the base class is
> 'Internal' - but if the base class is 'Public', then I don't see how
it
> would affect other classes.

I didn't say it affects other classes; I mean it forces the visibility
of the base members to at least be internal.
But if you didn't want that, you have to compromise your design.

And if the framework/tool supported this facility as a built-in feature,
it would either only be applicable in a very small subset of cases, or
would remove the ability to have private members - think outside your
immediate needs and think about the general case (which is what the
framework/tools guys have to)

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com