Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. class Trida {
  2. protected:   // všimni si, že je zde protected namísto private
  3.     int* foo;
  4. public:
  5.     Trida() : foo(NULL) {}
  6.     Trida(Trida* other) {
  7.         this->foo = other.foo;
  8.         // mělká naivní kopie
  9.         // hodně naivní, jenom pro příklad
  10.     }
  11.  
  12. };
  13.  
  14. class TridaDeepCopy {
  15. public:
  16.     TridaDeepCopy(Trida* other) {
  17.         this->foo = new int[other->pocet];
  18.         this->foo = ...
  19.         // deep copy
  20.     }
  21. };
  22.  
  23.  
  24. int main() {
  25.     Trida* x = new Trida();
  26.     x->něco(blabla);
  27.  
  28.     Trida* hlubokakopie = new TridaDeepCopy(x);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement