{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Allocaon deallocaon correctly if a class denes one of

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: py constructor (create a new copy of the parameter object) •  Returning object from a func/on: –  involves copy constructor (create a new copy of the return object) •  Assigning the returned object to a variable: –  Involves assignment operator (overwrite the exis/ng object) 2 10/5/12 The rule of three •  When a class allocates memory dynamically (new) in its constructor, it requires every copy of the object to deal with the memory alloca/on/ de ­alloca/on correctly. •  If a class defines one of the following, it should probably explicitly define all three: –  Copy constructor (memory alloca/on) –  Assignment operator (memory alloca/on/de ­ alloca/on) –  Destructor (memory de ­alloca/on) Operator member func/on •  Index operator (operator) and assignment operator (operator=) have to be member func/on if defined. •  When a binary operator is defined as a member func/on, its...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online