>Is that why you are using the header file ?
The standard library already defines date and time functions and types (inherited from C). The reside in the header. The ones I used were the tm struct, time_t, localtime, and mktime.
>yours is much more complicated!
Only if you aren't familiar with date and time handling in the standard library. The complexity in your version comes from operator+, where you have a loop and a bunch of magic numbers. A reader would need to verify that your math is correct as well as the algorithm performing the math. In my version it's a simple matter of making sure that I passed all of the right types to mktime and localtime. So the complexity is only skin deep.
>what advantage has your version got over mine?
Portability because the standard library handles the nitty gritty stuff. Flexibility because while you would need to design, implement, and test new features (such as adding seconds) with extensive algorithmic changes, I would only need to make a few minor and easily checked modifications. And scalability because by adding features your code will grow by leaps and bounds, mine will grow by only a handful of lines even if a lot of new functionality is added.
>What is the difference in using *this and time(hours, minutes) in my program
The former makes a copy of itself and returns it, the latter creates a new object. It's a subtle difference, and both will generally work the same with this class.
>I know '*this' is a pointer, but pointer for/from what ?
this could be better called self. It's a pointer to the object that the member functions are called on behalf of. So if I'm an object of L33tCoder, then this points to me, and *this is me.
>By using time(hours, minutes), is this related towards the constructor ?
Yes, you're calling the constructor directly and returning the result. It's just the same as saying:
time temp ( hours, minutes );
return temp;
In theory at least. Your compiler is more likely to optimize away any temporary objects by returning the constructor directly rather than creating your own temporary object.:
return temp ( hours, minutes ); // More likely to be optimized
>does it matter in wich order you write private and public in a class?
It can, but you're not likely to encounter such a situation for quite a while. ;)
>Could I write this piece shorter, not using your alternative?
cout<<"The time is now: "<< setw(hours < 10 ? 2 : 0) << hours <<" Hr "<< minutes <<"."<<endl;
Would be a start.