c++ - Is my code creating a deep or shallow copy of my object? -
i have code takes stack made of external pointer , internal pointers linked lists, can't tell if it's making deep or shallow copy though. if don't have enough information i'm sorry, think need tell though. thank you!
void stackclass::operator =(const stackclass& orig) { //stack = nullptr; node* temp = orig.stack; if (!orig.isempty()) { while (temp != null) { stack = orig.stack; // sets thew new stack equal old stack's value temp = temp->next; } // end while loop } // end if else { stack = nullptr; // sets empty list because there's no values } // end else }
in case it's copying pointer i.e shallow copy in effect.
deep copy means rather copying pointer explicitly allocate memory new pointer , store contents of passed in pointer code happens missing...
Comments
Post a Comment