Constructors (starstruck noob from C++)
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Jan 21 01:51:33 PST 2011
On 1/20/11 11:28 PM, Robert Jacques wrote:
> On Thu, 20 Jan 2011 22:02:42 -0500, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
> First, why not use tupleof? b.tupleof = a.tupleof; works perfectly fine,
> simpler and ahem, actually works. __traits(getMember, ...) has to obey
> scoping rules, so using it with a class that defines private variables
> results in a message like class hello.A member x is not accessible.
> Furthermore, you need to filter allMembers by a lot more than just
> function and "Monitor" as it also includes enum constants, etc. Having
> tried using it for serialization, I know it's non-trivial to use
> correctly, if you only want the actual data fields.
>
> i.e.
>
> void copyMembers(A)(A src, A tgt) if (is(A == class)) { tgt.tupleof =
> src.tupleof; }
Indeed, that's the canonical solution. Thanks for the reminder.
Andrei
More information about the Digitalmars-d
mailing list