Re: Initializing With a Base Class Instance

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



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


Relevant Pages

  • Re: Protected static members, abstract classes, object composition vs. subclassing
    ... unpublished and unknown ECMA 262 4th edition, JScript.net and JavaScript ... combination of a constructor function and its prototype define a process ... Rendering something 'private' is a matter of making it ... 'Private instance members' may be created by having the constructor (or ...
    (comp.lang.javascript)
  • Re: applets, applications and static declarations
    ... Abstract classes and interfaces can have static members, but neither can have direct instances. ... I assumed the application alone26 did not need a constructor ... static myGui myGui; ...
    (comp.lang.java.programmer)
  • Re: Creating a C++ like message loop in .NET threaded classes.
    ... API functions I wrote a base class that starts a thread in its constructor ... >> writing a singleton class that, at run time, will have its members invoked ...
    (microsoft.public.dotnet.framework)
  • Re: Is CppUnit un-C++
    ... > members instead of pointers. ... class type members as opposed to using pointers to class types as members. ... The issue of header files is really irrelevant in this case. ... should be a constructor and tearDownshould be a destructor. ...
    (comp.lang.cpp)
  • Re: no default constructor -- bad form?
    ... > default constructor? ... I wouldn't base any aspect of my design on "hearing that such-and-such is ... instance it allows you to put members of your class into a container. ... to put them in standard containers no matter what they point to. ...
    (comp.lang.cpp)