Newbie: copy, assignment of class instances

Larry Luther larry.luther at dolby.com
Thu May 20 11:46:37 PDT 2010


Given:

  class A {
    int x, y;
  }

  class B : A {
    int z;
  }

  B
    foo = new B,
    bar = new B;

  scope B
    alpha = new B;

Q1:  How do I copy the member variables contributed by base class A
     from "foo" to "bar"?
     In C++:  (A &) bar = foo;

Q2:  How do I do a deepcopy of foo to bar?
     In C++:  bar = foo;

Q3:  Is the object "alpha" on the stack (per documentation)?

Q4:  What happens when I do "alpha = foo;"?
     "printf( "%p\n", alpha);" indicates that the address of "alpha" has changed.

Thanks, Larry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100520/a1caef61/attachment.html>


More information about the Digitalmars-d-learn mailing list