Re: Initializing With a Base Class Instance
- From: <s>
- Date: Sun, 2 Jul 2006 11:52:37 -0500
JB suggested that you could use reflection. Since Base has a bunch of member variables - the copy constructor could use reflection to get the set of member variables - and then iterate through them all. That way, the copy constructor will be compact, will not have to know explicitly about any member variable and, perhaps most valuably, will dynamically handle new member variables as they are added.
Chris TR
"Jamie Hankins" <JamieHankins@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:43C14E2E-9F14-4722-981A-CAB5835D15A3@xxxxxxxxxxxxxxxx
In my real-world problem, "Base" is a class with tons of members, and I don't
want to introduce a new maintenance issue of keeping the copy constructor in
sync with new members. Also, "Base" is in code that another developer owns.
I think you're ultimately right, though. I'm going to e-mail the developer
that owns "Base" (obviously not its real name) and ask about adding a copy
constructor. If not, then I'll just rework "Decendant" to contain a "Base"
as a member instead of inheriting from it.
Thanks for the suggestions.
Jamie
>
> Why would you try and avoid modifying the base class ? Copy constructors are
> a common feature in any hierarchy that implements IClonable; in fact, I
> believe C++ creates a default copy constructor anyway.
>
> Joanna
- Prev by Date: Re: Webbrowser and images (how not to display them)
- Next by Date: Re: Webbrowser and images (how not to display them)
- Previous by thread: Re: Webbrowser and images (how not to display them)
- Next by thread: How can I whip up a "designer window" in Visual Studio 2005?
- Index(es):
Relevant Pages
|