We can return a reference timetype timetypeoperator

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: e a value. So we must return a reference to the instance we So have just copied to. have Applied Programming Applied Programming TimeType& TimeType::operator= (const TimeType& from) (const TimeType { // code here to copy the members of from // to this object return *this; return *this } W e are returning the dereference of this We this – which is the address of the current instance. We can return a reference. TimeType& TimeType::operator= TimeType::operator (const TimeType& from) (const TimeType { // code here to copy the members of from // to this object return *this; } So now we can say t1 = t2 = t3; So what's so special about = ? So Applied Programming TimeType& TimeType::operator= TimeType::operator (const TimeType& from) (const TimeType { // code here to copy the members of from // to this object return *this; } If we are actually doing t1 = t1; t1 t1 then we have to avoid freeing up existing then dynamic data of the current instance. dynamic So we need tests for this == &from So this Beware of dynam...
View Full Document

Ask a homework question - tutors are online