programminga general overview int fintcell }intcell aintcell cc ba write )cout < read<endl < read<endl < read<endlreturn figure simple function that exposes problems in figure the copy assignment operator at lines - uses standard idiom of checking for aliasing at line ( self-assignmentin which the client is making call obj=objand then copying each data field in turn as needed on completionit returns reference to itself using *this in ++ copy assignment is often written using copy-and-swap idiomleading to an alternate implementation intcell operatorconst intcell rhs intcell copy rhsstd::swap*thiscopy )return *this/copy assignment line places copy of rhs into copy using the copy constructor then this copy is swapped into *thisplacing the old contents into copy on returna destructor is invoked for copycleaning up the old memory for intcell this is bit inefficientbut for other typesespecially those with many complex interacting data membersit can be reasonably good default notice that if swap were implemented using the basic copy algorithm in figure the copy-and-swap idiom would not workbecause there would be mutual nonterminating recursion in ++ we have basic expectation that swapping is implemented either with three moves or by swapping member by member the move constructor at lines and moves the data representation from rhs into *thisthen it sets rhsprimitive data (including pointersto valid but easily destroyed state note that if there is non-primitive datathen that data must be moved in the initialization list for exampleif there were also vector itemsthen the constructor would beintcellintcell &rhs storedvaluerhs storedvalue }itemsstd::moverhs items rhs storedvalue nullptr/move constructor