Problems with default constuctor

I wrote this code for my class, but I cannot get the second class to call the default constructor. Please help and any assistance would greatly be appreciated. The first class works, but I cannot get the second one to call the first constructor. The header file constains all prototypes and private data members (I have not included it).


#include <iostream>
#include "CheapWatch.h"

using namespace std;

int main()
{

long num = 18637;
CheapWatch milTime( num );

CheapWatch newTime();


}



CheapWatch::CheapWatch()
: hours( 0 ), minutes( 0 ), seconds( 0 )
{
long temp = 0;
cout << " Please input the total number of seconds : ";
cin >> temp;
cout << endl;
CheapWatch temp1( temp );
}

CheapWatch::CheapWatch( long &secs )
: hours( 0 ), minutes( 0 ), seconds( 0 )
{
setTime( secs );
}

CheapWatch::~CheapWatch()
{
printMilTime();
}

void CheapWatch::setTime( long total )
{
setHours( total );
setMinutes( total );
setSeconds( total );
}

void CheapWatch::setHours(long hrs)
{
hours = static_cast<int>(hrs / 3600.);
}

void CheapWatch::setMinutes(long mins)
{
minutes = static_cast<int>((mins - (hours *3600.))/60);
}

void CheapWatch::setSeconds(long secs)
{
seconds = static_cast<int>(((secs - (hours * 3600.))- minutes * 60));
}

unsigned int CheapWatch::getHours() const
{
return hours;
}

unsigned int CheapWatch::getMinutes() const
{
return minutes;
}

unsigned int CheapWatch::getSeconds() const
{
return seconds;
}

void CheapWatch::printMilTime() const
{

cout << setfill('0') << setw( 2 ) << getHours() <<":" << setw( 2 ) << getMinutes() << ":" << setw( 2 ) << getSeconds() << endl;
}


Last edited on
CheapWatch newTime();
The compiler will see this as a function declaration. A function named newTime that returns a CheapWatch. Remove the parenthesis and the compiler will understand.
CheapWatch newTime;
You are so helpful. Thank you so much. It was so simple but I could not see it and as soon as you said it I was like OHHH. Again thank you.
Topic archived. No new replies allowed.