i have a source code for a clock, and after compiling it, it returns an error. i've tried it in a console app (which i was told it's to be done in) and a win32 app, but returned the same error. the code is:
// Clock to show overloading
// Title: clock
#include <iostream>
using namespace std;
class clock
{
long int tot_secs, secs, mins, hours, days;
public:
clock(long i); // constructor and conversion
void print() const; // formatted printout
void tick(); // add one second
clock operator++() { this -> tick(); return(*this); }
// change to have consistent interface for postfix++
clock operator++(int) { clock temp = *this; tick(); return temp; }
void reset (const clock& c);
// make all binary operators friends
friend clock operator+(clock c1, clock c2);
friend clock operator-(clock c1, clock c2);
friend clock operator*(long m, clock c);
friend clock operator*(clock c, long m);
friend outstream& operator<<(ostream& out, const clock& c);
};
inline clock::clock(long i):tot_secs(i)
{
secs = tot_secs % 60;
mins = (tot_secs / 60 ) % 60;
hours = (tot_secs / 3600) % 24;
days = tot_secs / 86400;
}
// redone to be concise - use conversion constructor and default =
void clock::tick()
{
*this = ++total_secs;
}
// redone to use defalt =
void clock::reset(cont clock& c)
{
*this = c;
}
clock operator+(clock c1, clock c2)
{
return(c1.tot_secs + c2.tot_secs);
}
clock operator-(clock c1, clock c2)
{
return(c1.tot_secs + c2.tot_secs);
}
clock operator*(long m, clock c)
{
return (m * c.tot_secs);
}
clock operator*(clock c, long m)
{
return (m * c); // keep tied to above
}
// overload operator <<
ostream& operator<<(ostream& out, const clock& c)
{
out << c.days << " days, " << c.hours << " hours, "
<< c.mins << " minutes, " << c.secs << " seconds.\n";
return out;
}
int main()
{
clock t1(59), t2(172799); // min-1 sec and 2 days-1 sec
clock t3(0);
clock c1(900), c2(400);
cout << "initial times are\n" << t1 << t2;
++t1; ++t2; // t1++; t2++ are also possible
cout << "after one second times are\n" << t1 << t2;
// more tests
t3 = t1 + t2;
cout << t3;
t3 = t1 * 5;
cout << t3;
t3 = 6 * t3;
cout << t3;
t3 = t3 - t1;
cout << t3;
c1.reset(c2);
c2.reset(100);
cout << "\nc1 and c2\n" << c1 << c2;
}
and i won't forget to copy the error so u know what's going on:
--------------------Configuration: clock2 - Win32 Debug--------------------
Compiling...
clock.cpp
c:\program files\microsoft visual studio\myprojects\clock2\clock.h(21) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.
clock2.exe - 1 error(s), 0 warning(s)
this is the first time i've crossed this error. if anyone can help, let me know. i would check the help menu like it says in the error to do so, but usually it doesn't help, and i don't like technical support. if u can help, it'd be appreciated. thx