friend functions and Visual C++ 6.0

This compiler is driving me up the wall! I'm

trying to declare a friend function, which is an

overloaded addition operator. I've tried

everything to figure out what I'm doing wrong, but

nothing has helped. In fact, when I cut and paste

the code (below) that Microsoft furnishes as

example of a friend function, it doesn't work

either! I keep on getting the following error:

D:Oopincpp3eSourceCh11Frengl.cpp(55) : 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

I would call tech support if it weren't for the price...$95...

Here's the Microsoft sample code that I mentioned above:


using namespace std;

class Complex



Complex( float re, float im );

friend Complex operator+( Complex first, Complex second );


float real, imag;


Complex operator+( Complex first, Complex second )


return Complex( first.real + second.real,first.imag + second.imag );


In my program, I had a simple main() to test it,

but that obviously isn't the problem (if you don't believe me, read on).

Also, here's some other code that I got from the

book "Object-Oriented Programming in C++" by the

Waite Group, for which I get the exact same error as mentioned above:


using namespace std;

class Distance //English Distance class



int feet;

float inches;


Distance() //constructor (no args)

{ feet = 0; inches = 0.0; }

Distance( float fltfeet ) //constructor (one arg)

{ //convert float to Distance

feet = int(fltfeet); //feet is integer part

inches = 12*(fltfeet-feet); //inches is what's left


Distance(int ft, float in) //constructor (two args)

{ feet = ft; inches = in; }

void showdist() //display distance

{ cout << feet << "'-" << inches << '"'; }<br>
friend Distance operator + (Distance, Distance); //friend



Distance operator + (Distance d1, Distance d2) //add D1 to d2


int f = d1.feet + d2.feet; //add the feet

float i = d1.inches + d2.inches; //add the inches

if(i >= 12.0) //if inches exceeds 12.0,

{ i -= 12.0; f++; } //less 12 inches, plus 1 foot

return Distance(f,i); //return new Distance with sum



int main()


Distance d1 = 2.5; //constructor converts

Distance d2 = 1.25; //float-feet to Distance

Distance d3;

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

d3 = d1 + 10.0; //distance + float: OK

cout << "
d3 = "; d3.showdist();<br>
d3 = 10.0 + d1; //float + Distance: OK

cout << "
d3 = "; d3.showdist();<br>
cout << endl;<br>
return 0;


As you can see, something is seriously wrong.

Could it be that a setting on my compiler needs to

be changed? Any help would be greatly appreciated!


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!