Default timetype starttime starttime now timetype

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: nd TimeType::TimeType() { hours = minutes = seconds = 0; } So let's do it. Applied Programming This is called a default constructor, as it provides This default as no user-settable initial value. no to the implementation. Applied Programming Arrays of classes cannot be declared without a Arrays default constructor. default TimeType* starttime; starttime Now TimeType deadline; starttime = new TimeType[7]; will allocate the space and set deadline to will deadline to represent time 00:00:00. represent If we don't provide a default constructor, C++ If does (but with no initialisation). does Applied Programming creates and initialises 7 instances. But what if we want to give a different initial But value? value? We define a different constructor. Applied Programming TimeType(int,int,int); So now with implementation TimeType start(10,20,30); TimeType::TimeType(int h, int m, int s) h, int m, int { hours = h; minutes = m; seconds = s; } Hey! Don't we then have two functions with the Hey! same name? same Yes – with different arguments. Yes will create the var...
View Full Document

Ask a homework question - tutors are online