Sign in to follow this  

error ...

This topic is 3660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Theres some errors in your code.

Here is the revised code with the errors pointed out and fixed...

// 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);

// ERROR: outstream doesnt exist
// friend outstream& operator << (ostream& out, const clock& c);

friend ostream& 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; // ERROR: total_secs doesnt exist
*this = ++tot_secs;
}
// redone to use defalt =

//void clock::reset(cont clock& c) // ERROR: "cont" is not a keyword

void clock::reset(const 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;
}

I dont see anything else wrong with the code (Excluding improvements on the code), and it should work fine now.

Hope this helps!

Share this post


Link to post
Share on other sites
i thank u for trying to help, but i still get the same error. i don't expect some genius to just come out of nowhere and answer everything for me, but i certainly appreciate u tried, but also, if anyone else may know the problem, could u help? thx

Share this post


Link to post
Share on other sites
i use Visual C++ 6.0. idk if it's an inferior version or not, it's just what i could get my hands on at the time.

i've tried renaming the class "time" but it still does the same thing. i'm not too familiar with working on classes, so i don't know how to use them. but they shouldn't affect the program, should they?

also, would getting Visual C++ 2005 from the Microsoft site be better than C++ 6.0? just curious

Share this post


Link to post
Share on other sites
Quote:

also, would getting Visual C++ 2005 from the Microsoft site be better than C++ 6.0? just curious

Visual C++ 6 is an old, pre-standard buggy compiler, so yes, I highly recommend upgrading to Visual C++ 2005.

Share this post


Link to post
Share on other sites

This topic is 3660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this