Timetype to int and timetype timetype t1123 t2 t2 t1

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: ) W e'll explain the first const soon. We'll const Applied Programming const TimeType TimeType::operator+(int r_op) const const TimeType { TimeType temp(hours,minutes,seconds+r_op); // code here to make values within range return temp; } Applied Programming So now we can say So, what do we need to be able to add a So, TimeType to an int and get a TimeType? TimeType to int and TimeType TimeType t1(1,2,3), t2; t2 = t1 + 10; W e need an operator+ function with an int as We operator+ function int as its left operand and a TimeType as its right TimeType as operand. operand. BUT we cannot say t2 = 10 + t1 as this has an int lleft operand and TimeType as int eft TimeType right operand. See how complex this gets! We need const TimeType operator+(const TimeType&); const TimeType iin the int class n int Applied Programming Applied Programming So, what do we need to be able to add a So, TimeType to an int and get a TimeType? TimeType to int and TimeType It is not likely that such a function would exist for It int, nor should it. int W e need an operator+ functi...
View Full Document

Ask a homework question - tutors are online