Howdy, Stranger!

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

Categories

friend operator function shows internal compiler error

kudilkrishnakudilkrishna Member Posts: 1
Hi All,

This is my first post in programmers heaven.

I got an Internal Compiler Error while running this program

this is the exact program from 'C++ The complete Reference' 4th Edition Author - Herbet Schildt

this program was compiled in vc++ 6.0

here is the code

//this program is from c++ complete reference 4th editon pg no 397
//this program was compiled under microsoft visual C++ 6.0


// there is internal compiler error for Note 1
#include
using namespace std;

class loc {
int longitude, latitude;
public:
loc() {}
loc(int lg, int lt) {
longitude = lg;
latitude = lt;
}

void show() {
cout << longitude << " ";
cout << latitude << "
";
}
// Note 1 the below line has some error, compiler reporting as internal compiler error.
friend loc operator+(loc op1, int op2);
friend loc operator+(int op1, loc op2);
};

// + is overloaded for loc + int.
loc operator+(loc op1, int op2)
{
loc temp;

temp.longitude = op1.longitude + op2;
temp.latitude = op1.latitude + op2;

return temp;
}
// + is overloaded for int + loc.
loc operator+(int op1, loc op2)
{
loc temp;

temp.longitude = op1 + op2.longitude;
temp.latitude = op1 + op2.latitude;

return temp;
}

int main()
{
loc ob1(10, 20), ob2( 5, 30), ob3(7, 14);

ob1.show();
ob2.show();
ob3.show();

ob1 = ob2 + 10; // both of these
ob3 = 10 + ob2; // are valid

ob1.show();
ob3.show();

return 0;
}


Sign In or Register to comment.