Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Trida {
- protected: // všimni si, že je zde protected namísto private
- int* foo;
- public:
- Trida() : foo(NULL) {}
- Trida(Trida* other) {
- this->foo = other.foo;
- // mělká naivní kopie
- // hodně naivní, jenom pro příklad
- }
- };
- class TridaDeepCopy {
- public:
- TridaDeepCopy(Trida* other) {
- this->foo = new int[other->pocet];
- this->foo = ...
- // deep copy
- }
- };
- int main() {
- Trida* x = new Trida();
- x->něco(blabla);
- Trida* hlubokakopie = new TridaDeepCopy(x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement