code_junkie

What's wrong with Copy Constructors? Why use Cloneable interface?

Nov 13th, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. SomeClass x = new SomeClass();
  2.  
  3. SomeClass* x = new SomeClass();
  4.  
  5. *x = *another_x;
  6.  
  7. class A {
  8. public A(A c) { aMember = c.aMember }
  9. int aMember;
  10. }
  11.  
  12. class B : A {
  13. public B(B c) : base(c) { bMember = c.bMember }
  14. int bMember;
  15. }
  16.  
  17. class GenericContainer {
  18. public GenericContainer(GenericContainer c) {
  19. // XXX Wrong code: if aBaseClass is an instance of B, the cloned member won't
  20. // be a B instance!
  21. aBaseClass = new A(c.aBaseClass);
  22. }
  23. A aBaseClass;
  24. }
Add Comment
Please, Sign In to add comment