if(!isValid) you're still left with a Time object (0,0,0) which you probably don't want. So it's best to delete this ctor altogether and use isValid() to check the incoming data first and only then to pass the data to a setter method
for printing Time objects, since you're already using std::tm, you can also use std::put_time() passing a reference to a std::tm object initialized with your Time object data values: http://www.cplusplus.com/forum/beginner/208986/#msg983688
Above link also shows how you could use std::duration_cast to overload addition and subtraction operators for Time objects and for the current increment methods in class Time
Incidentally the int's passed to the ctors and the increment methods could be const qualified
void Time::incrementMinutes(int m)
{
if (m >= 0)
{
min += n;
normalize();
}
}
Generally it's a good idea to store the data in a format friendly to the computer rather than the human. Convert to a human-friendly format when you have to. Following that principle, I would have stored a single int to store the number of seconds. That makes the incrementXYZ() functions trivial. It also means the check for AM vs PM is trivial and you only have to convert to hours, minutes and seconds when the user wants it.
Where do I define the delete function for the constructor? Inside the class?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
struct Time
{
int hr;
int min;
int sec;
Time(){}
Time (constint& h, constint& m, constint& s)=delete;
};
int main()
{
Time t;//OK
Time u(1,2,3);//error: use of deleted function 'Time::Time(const int&, const int&, const int&)'|
}