Student having some problems with friend overload functions 
Author Message
 Student having some problems with friend overload functions

Hi group, I am teaching myself C++ as you know, so excuse the constant
postings to this group. You have helped a lot and I am appreciative of it.
Anyway, heres my problem:

I am practising overloading operators, I can successfully compile a program
that is a member of a class, but when the overload function is a freind of a
class, the program won't compile nor will it give me a discription of what
is going on (The error has been added to the code below). I have tried
declaring and defining the function several ways, all of which produce the
same error. I am using Microsoft C++ 6.0 and have not 'fiddled' with the
compilers parameters or any of the settings. I have typed the code exactly
as it was in the book.

Is there something that I am not doing? I hope someone could shed some light
on this.... Thanks in advance.

Heres the code:

[start snip]

#include <iostream>
using namespace std;

class MyClass {
public:
 MyClass() {};
 MyClass(int x, int y) { var1 = x, var2 = y; }

 void show() { cout << var1 << " " << var2 << endl; }

 /*

The declaration of the following friend function, causes this error:

  C:\Ioan`s Stuff\Personal\Programming Stuff\Visual C++\Rc\RC.cpp(11) :
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.
 */

 friend MyClass operator+(MyClass x, MyClass y);
private:
 int var1, var2;

Quote:
};

MyClass operator +(MyClass x, MyClass y) {
 MyClass temp;

 temp.var1 = x.var1 + y.var1;
 temp.var2 = x.var2 + y.var2;

 return temp;

Quote:
}

void main() {
 MyClass ob1(10, 20), ob2(30, 40), ob3;

 cout << "\nValues passed to constructor\n";
 cout << "ob1: ";
 ob1.show();

 cout << "ob2: ";
 ob2.show();

 cout << "\nAdding ob1 to ob2; assigning values to ob3\n";
 ob3 = ob1 + ob2;

 cout << "\nPerformed Addition\n"; file://Notify User

 cout << "\nValues after addition\n";
 cout << "ob3: ";
 ob3.show();

 file://New line before press any key...
 cout << endl;

Quote:
}

[end snip]

--
Registered Linux user number 182404
The only thing that matters is the force of one's expression
--
Please remove NOSPAM from address to repy



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Student having some problems with friend overload functions

2. Problems using Friend function

3. Problem with Friend Function

4. Why warn about: Friend Overridable Sub / Friend MustOverride Sub

5. Overloading the Save / Save As functions in Word.

6. Overloading the Save / Save As functions in Word.

7. Overloading the Save / Save As functions in Word.

8. How to overloads function with only different return

9. How to overloads Function with return different only (all parameter are the same)

10. Function overloading and Optional parameters

11. Public Overloads Overrides Function Equals()

12. Casting in overloaded functions?

 

 
Powered by phpBB® Forum Software