Hi,

Could anyone explain me above error?

// friend overload + operator function

#include<iostream>
using namespace std;

class Distance
{
private:
	int feet;
	float inches;
public:
	Distance() { feet = 0; inches = 0.0; }
	Distance(float f)
	{
		feet=int(f);
		inches = 12*(f-feet);
	}

	Distance(int ft, float in)
	{
		feet = ft;
		inches = in;
	}

	void showdist()
	{
		cout << feet << "\'-" << inches << "\"";
	}

	friend Distance operator+(Distance, Distance);
};

Distance operator+(Distance d1, Distance d2)
{
	int f=d1.feet + d2.feet;
	float i=d1.inches + d2.inches;

	if (i>12.0)
	{ f++; i-=12.0; }

	return Distance(f,i);
}

int main()
{
	Distance d1=2.5;
	Distance d2=1.25;
	Distance d3;

	cout << "d1 = "; d1.showdist();
	cout << "d2 = "; d2.showdist();

	d3=d1+10.0;

	cout << "d3 = "; d3.showdist();		// distance + float

	d3=10.0+d1;

	cout << "d3 = "; d3.showdist();		// float + distance
	
	return 0;
}

After compile above sample code, I get the following error. fatal error C1001: INTERNAL COMPILER ERROR May be I am a beginner and always get an error :confused: although I run the simple code.:icon_smile:

Just out of curiosity, could you post the complete error message, i.e. including also the line number which causes this.

I think your code should compile as such, so there is actually a problem with your compiler in this case (I suppose it is VC 6.0 or earlier?). In that case, you could grab yourself e.g. VC 2005 or 2008 Express and/or CodeBlocks, which are free.

This is what the documentation states about this error:

INTERNAL COMPILER ERROR
(compiler file file, line number)

The compiler cannot generate correct code for a construct, probably due the combination of an expression and an optimization option. Try removing one or more optimization options and recompiling the function containing the line indicated in the error message.

You can probably fix the problem by removing one or more optimization options. To determine which option is at fault, remove options one at a time and recompile until the error message goes away. The options most commonly responsible are /Og, /Oi, and /Oa. Once you determine which option is responsible, you can disable it using the optimize pragma around the function where the error occurs and continue to use the option for the rest of the module.

So there are some chances that you can overcome this with your current compiler.

These all are error codes.

--------------------Configuration: example 7 - Win32 Debug--------------------
Compiling...
example 7.cpp
c:\documents and settings\Administrator\desktop\testing (c++)\chapter 7 example 7\example 7.cpp(30) : 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.

example 7.exe - 1 error(s), 0 warning(s)

works well in VC 2008 express edition...i think you should follow mitrmkar..suggestion or download VC 2008 express edition which is free

OK, seems its the friend Distance operator+(Distance, Distance ); that's causing the error.

Anyhow, as said, the code should compile, so wouldn't that be a good sign for you to upgrade your compiler to a much more modern one?? Of course you can keep the old one alongside, if you want, for any reason.

Hi all,

You all are right. I am using Microsoft VC++ 6.0 . I also see where the error is, but I don't know what the problem is.
If so, I need to change a new version software to run it?

Thanks a lot,
zawpai

First thing would be make sure you have the latest service pack for the compiler. There has been like 5 or 6 service packs for that compiler.

Or just upgrade to the latest visual studio express.

make sure you have the latest service pack for the compiler. There has been like 5 or 6 service packs for that compiler.

I am not understanding what it means. I will upgrade to the latest visual studio express.

I am not understanding what it means. I will upgrade to the latest visual studio express.

Service packs are software distributions that supply bug fixes, for VS 6.0, you can download service pack 5 from
http://msdn.microsoft.com/en-us/vstudio/aa718363.aspx

Note that the Express edition does not include MFC, so you may want to keep the VS 6.0 installation too i.e. don't uninstall it. You can have an Express edition and VS 6.0 both installed on your computer.

(I suppose it is VC 6.0 or earlier?). In that case, you could grab yourself e.g. VC 2005 or 2008 Express and/or CodeBlocks, which are free.

hi!

I have now this problem too.
Could you explain how can I get those things you were talking about?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.