/*
Time.h
*/
#ifndef TIME_H
#define TIME_H
class Time
{
public:
Time();
//Time(int, int, int);
virtual ~Time();
void setTime(int, int, int);
void printUniversal();//print the time in universal format
void printStandard();
protected:
private:
int hour;//from 0-23
int minute;//0-59
int second;//0-59
};
#endif // TIME_H
/*
Time.cpp
definition of the member functions of the Time class
*/
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>
using std::setfill;
using std::setw;
#include "Time.h"
Time::Time()//ERROR HERE!
{
hour = minute = second = 0;
}
/*
//second constructor
Time::Time(int hour, int minute, int second)
{
this->hour = hour;
this->minute = minute;
this->second = second;
}
*/
void Time::setTime(int h, int m, int s)
{
//the assignements are done if just the validation returns true
hour = (h >= 0) && (h < 24)? h : 0;
minute = (h >= 0) && (m < 60)? m : 0;
second = (s >= 0) && (s < 60)? s : 0;
}
void Time::printUniversal()
{
cout << setfill('0') << setw(2) << hour << ":" << setw(2)
<< minute << ":" << setw(2) << second << ":";
}
/*
Time.h
*/
#ifndef TIME_H//directives to the preprocessor
#define TIME_H
class Time
{
public:
Time();
Time(int=0, int=0, int=0);
virtual ~Time();
void setTime(int, int, int);
void printUniversal();//print the time in universal format
void printStandard();
protected:
private://each public member should be private, except in an clearly demonstrable case: this the "Principle of least privilege"
int hour;//from 0-23
int minute;//0-59
int second;//0-59
};
#endif // TIME_H
I found out why: the constructor with default arguments had become the default constructor and a class can just have 1 default costructor, which isn't the case!
Thanks anyway!