We were given our original project back and asked to overload all the operators, even if we did use them we had to overload them. The teacher said we would have to rewrite some of our code to make the overloading work. I am clueless as to even how to begin to implement overloading.

Here is my original code: It reads in a file that holds the scores of students, then outputs the data into another file with each student's average appended to the end and the overall average for each test(quiz1 quiz2 etc....) underneath their respective column.

Code:
```#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;

{
public:
Grades(int quiz1, int quiz2, int midterm, int final);
void Input(ifstream& Fin);
void Output(ofstream& Fout);
int GetQuiz1();
int GetQuiz2();
int GetMidterm();
int GetFinal();
void SetQuiz1(int NewQuiz1);
void SetQuiz2(int NewQuiz2);
void SetMidterm(int NewMidterm);
void SetFinal(int NewFinal);

private:
int mQuiz1;
int mQuiz2;
int mMidterm;
int mFinal;
};

int main()
{
Grades Sum; //will be used to get average of all quizes
double Avg;
double Quiz1TotalAverage;
double Quiz2TotalAverage;
double FinalTotalAverage;
double MidtermTotalAverage;

ifstream Fin;
ofstream Fout;

Fin.open("input.txt");
if(Fin.fail())
{
cout << "Input file opening failed.\n";
exit(1);
}

Fout.open("output.txt");
if(Fout.fail())
{
cout << "Output file opening failed.\n";
exit(1);
}

Fout << " Quiz1 " << " Quiz2 " << " Midterm " << "      Final " << " Average " << endl;

while(!(Fin.eof()))
{
Student.Input(Fin);
Student.Output(Fout);
Avg = 20.0 * (Student.GetQuiz1() + Student.GetQuiz2())/20 + (20.0 * Student.GetMidterm())/100 + (60.0 * Student.GetFinal())/100;
//calculates the averages for the whole class for quiz1, quiz2, midterm and final exams.
Sum.SetQuiz1(Sum.GetQuiz1() + Student.GetQuiz1());
Sum.SetQuiz2(Sum.GetQuiz2() + Student.GetQuiz2());
Sum.SetFinal(Sum.GetFinal() + Student.GetFinal());
Sum.SetMidterm(Sum.GetMidterm() + Student.GetMidterm());
Fout << setw(10) << Avg << endl;
}
//the total average for each quiz, midterm and final is set equal to a variable
//whose value will be output to the output file
Quiz1TotalAverage = Sum.GetQuiz1()/15;
Quiz2TotalAverage = Sum.GetQuiz2()/15;
FinalTotalAverage = Sum.GetFinal()/15;
MidtermTotalAverage = Sum.GetMidterm()/15;

Fout << "___" << setw(10) << "___" << setw(10) << "___" << setw(10) << "___" << endl;
Fout << Quiz1TotalAverage << setw(10) << Quiz2TotalAverage << setw(10) << FinalTotalAverage << setw(10) <<MidtermTotalAverage;

Fin.close();
Fout.close();

return 0;

}

{
}

{
}

{
Fin >> mQuiz1 >> mQuiz2 >> mMidterm >> mFinal;
}

{
Fout << mQuiz1 << setw(10)<< mQuiz2 << setw(10)<< mMidterm << setw(10)<< mFinal;
}

{
return mQuiz1;
}
{
return mQuiz2;
}

{
return mMidterm;
}

{
return mFinal;
}

{
mQuiz1 = NewQuiz1;
}

{
mQuiz2 = NewQuiz2;
}

{
mMidterm = NewMidterm;
}

{
mFinal = NewFinal;
}```

Code:
```class Grades
{
public:
Grades(int quiz1, int quiz2, int midterm, int final);
void Input(ifstream& Fin);
void Output(ofstream& Fout);
int GetQuiz1();
int GetQuiz2();
int GetMidterm();
int GetFinal();
void SetQuiz1(int NewQuiz1);
void SetQuiz2(int NewQuiz2);
void SetMidterm(int NewMidterm);
void SetFinal(int NewFinal);

private:
int mQuiz1;
int mQuiz2;
int mMidterm;
int mFinal;
};

int main()
{

Grades Sum; //will be used to get average of all quizes
Code:
```Grades operator +(const Grades& Test1, const Grades& Test2)
{

temp = Test1.mQuiz1 + Test1.mQuiz2;

return temp;
}```

As stated before, I don't know what direction to go in and i have to overload
the + - * / == << and >> operators.

So where do i start? What needs to be replaced and what just needs to be augmented. Thank you in advance

2. From what I can gather, all my overloading will deal with what's in my while loop

3. Well, it's really easy to overload the stream extraction/insertion operators (>> and <<). That can clean up the look of the loop a bit and you can get rid of the Input and Output functions:
Code:
```class Grades
{
public:
...
...
};

ostream& operator<<(ostream& os, const Grades& rhs)
{
return os << rhs.mQuiz1 << setw(10) << rhs.mQuiz2
<< setw(10) << rhs.mMidterm << setw(10) << rhs.mFinal;
}

{
return is >> rhs.mQuiz1 >> rhs.mQuiz2 >> rhs.mMidterm >> rhs.mFinal;
}```
Then the while loop can look like this:
Code:
```while(Fin >> Student)
{
Fout << Student;
...
}```
Now all you need is something (you'll have to make an attempt and show us what you've got) to handle the addition so you can have a Sum object and each iteration through the loop, you add (+) the current Student to the Sum object so you have a running total of all the different grades. Your addition operator should give you something similar to:
Code:
```Grades Student;
int counter = 0;
while( Fin >> Student )
{
Fout << Student;
Sum = Sum + Student; // Keep a running total of all the grades
++counter;
}
// Now output the averages```

4. Unbelievable, this helps me more then you know. I can't thank you enough.

5. i made the suggested alterations and overloaded my operators, but now the compiler is giving me errors having to deal with my functions' handling of private member variables.

Here is the code and erros

Code:
```#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;

{
public:
Grades(int quiz1, int quiz2, int midterm, int final);
friend ostream& operator <<(ostream& Outs, const Grades& Rhs);
friend istream& operator >>(istream& Ins, Grades& Rhs);

int GetQuiz1();
int GetQuiz2();
int GetMidterm();
int GetFinal();
void SetQuiz1(int NewQuiz1);
void SetQuiz2(int NewQuiz2);
void SetMidterm(int NewMidterm);
void SetFinal(int NewFinal);

private:
int mQuiz1;
int mQuiz2;
int mMidterm;
int mFinal;
};

int main()
{
Grades Sum; //will be used to get average of all quizes
double Avg;
double Quiz1TotalAverage;
double Quiz2TotalAverage;
double FinalTotalAverage;
double MidtermTotalAverage;
int counter = 0;

ifstream Fin;
ofstream Fout;

Fin.open("input.txt");
if(Fin.fail())
{
cout << "Input file opening failed.\n";
exit(1);
}

Fout.open("output.txt");
if(Fout.fail())
{
cout << "Output file opening failed.\n";
exit(1);
}

Fout << " Quiz1 " << " Quiz2 " << " Midterm " << "      Final " << " Average " << endl;

/*******************************************************************************
This loop executes until the entire file has been read and formula has been applied.
*******************************************************************************/

while(!(Fin.eof()))
{
Fin >> Student;
Fout << Student;
Avg = 20.0 * (Student.GetQuiz1() + Student.GetQuiz2())/20 + (20.0 * Student.GetMidterm())/100 + (60.0 * Student.GetFinal())/100;
Sum = Sum + Student; // Keeps a running total of all the grades
Fout << setw(10) << Avg << endl;
counter++;
}

//the total average for each quiz, midterm and final is set equal to a variable
//whose value will be output to the output file
Quiz1TotalAverage = Sum/counter;
Quiz2TotalAverage = Sumcounter;
FinalTotalAverage = Sum/counter;
MidtermTotalAverage = Sum/counter;

Fout << "___" << setw(10) << "___" << setw(10) << "___" << setw(10) << "___" << endl;
Fout << Quiz1TotalAverage << setw(10) << Quiz2TotalAverage << setw(10) << FinalTotalAverage << setw(10) <<MidtermTotalAverage;

Fin.close();
Fout.close();

return 0;

}

{
}

{
}

istream& operator >>(istream& Ins, Grades& Rhs)
{
return Ins >> Rhs.mQuiz1 >> Rhs.mQuiz2 >> Rhs.mMidterm >> Rhs.mFinal;
}

ostream& operator <<(ostream& Outs, const Grades& Rhs)
{
return Outs << Rhs.mQuiz1 << setw(10) << Rhs.mQuiz2
<< setw(10) << Rhs.mMidterm << setw(10) << Rhs.mFinal;
}

{

temp.mQuiz1 = Lhs.mQuiz1 + Rhs.mQuiz1;
temp.mQuiz2 = Lhs.mQuiz2 + Rhs.mQuiz2;
temp.mMidterm = Lhs.mMidterm + Rhs.mMidterm;
temp.mFinal = Lhs.mFinal + Rhs.mFinal;

return temp;
}

{

temp.mQuiz1 = Lhs.mQuiz1 - Rhs.mQuiz1;
temp.mQuiz2 = Lhs.mQuiz2 - Rhs.mQuiz2;
temp.mMidterm = Lhs.mMidterm - Rhs.mMidterm;
temp.mFinal = Lhs.mFinal - Rhs.mFinal;

return temp;
}

{

temp.mQuiz1 = Lhs.mQuiz1 / Rhs.mQuiz1;
temp.mQuiz2 = Lhs.mQuiz2 / Rhs.mQuiz2;
temp.mMidterm = Lhs.mMidterm / Rhs.mMidterm;
temp.mFinal = Lhs.mFinal / Rhs.mFinal;

return temp;
}

{

temp.mQuiz1 = Lhs.mQuiz1 == Rhs.mQuiz1;
temp.mQuiz2 = Lhs.mQuiz2 == Rhs.mQuiz2;
temp.mMidterm = Lhs.mMidterm == Rhs.mMidterm;
temp.mFinal = Lhs.mFinal == Rhs.mFinal;

return temp;
}*/

{

temp.mQuiz1 = Lhs.mQuiz1 * Rhs.mQuiz1;
temp.mQuiz2 = Lhs.mQuiz2 * Rhs.mQuiz2;
temp.mMidterm = Lhs.mMidterm * Rhs.mMidterm;
temp.mFinal = Lhs.mFinal * Rhs.mFinal;

return temp;
}

{
return mQuiz1;
}
{
return mQuiz2;
}

{
return mMidterm;
}

{
return mFinal;
}

{
mQuiz1 = NewQuiz1;
}

{
mQuiz2 = NewQuiz2;
}

{
mMidterm = NewMidterm;
}

{
mFinal = NewFinal;
}```

Code:
```c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(139) : error C2248: 'Grades::mQuiz1' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(35) : see declaration of 'Grades::mQuiz1'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(139) : error C2248: 'Grades::mQuiz1' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(35) : see declaration of 'Grades::mQuiz1'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(139) : error C2248: 'Grades::mQuiz1' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(35) : see declaration of 'Grades::mQuiz1'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(140) : error C2248: 'Grades::mQuiz2' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(36) : see declaration of 'Grades::mQuiz2'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(140) : error C2248: 'Grades::mQuiz2' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(36) : see declaration of 'Grades::mQuiz2'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(140) : error C2248: 'Grades::mQuiz2' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(36) : see declaration of 'Grades::mQuiz2'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(141) : error C2248: 'Grades::mMidterm' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(37) : see declaration of 'Grades::mMidterm'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(141) : error C2248: 'Grades::mMidterm' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(37) : see declaration of 'Grades::mMidterm'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(141) : error C2248: 'Grades::mMidterm' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(37) : see declaration of 'Grades::mMidterm'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(142) : error C2248: 'Grades::mFinal' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(38) : see declaration of 'Grades::mFinal'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(142) : error C2248: 'Grades::mFinal' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(38) : see declaration of 'Grades::mFinal'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(142) : error C2248: 'Grades::mFinal' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(38) : see declaration of 'Grades::mFinal'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(151) : error C2248: 'Grades::mQuiz1' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(35) : see declaration of 'Grades::mQuiz1'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(151) : error C2248: 'Grades::mQuiz1' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(35) : see declaration of 'Grades::mQuiz1'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(151) : error C2248: 'Grades::mQuiz1' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(35) : see declaration of 'Grades::mQuiz1'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(152) : error C2248: 'Grades::mQuiz2' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(36) : see declaration of 'Grades::mQuiz2'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(152) : error C2248: 'Grades::mQuiz2' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(36) : see declaration of 'Grades::mQuiz2'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(152) : error C2248: 'Grades::mQuiz2' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(36) : see declaration of 'Grades::mQuiz2'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(153) : error C2248: 'Grades::mMidterm' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(37) : see declaration of 'Grades::mMidterm'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(153) : error C2248: 'Grades::mMidterm' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(37) : see declaration of 'Grades::mMidterm'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(153) : error C2248: 'Grades::mMidterm' : cannot access private member declared in class 'Grades'
c:\documents and settings8\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(37) : see declaration of 'Grades::mMidterm'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(154) : error C2248: 'Grades::mFinal' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(38) : see declaration of 'Grades::mFinal'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(154) : error C2248: 'Grades::mFinal' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(38) : see declaration of 'Grades::mFinal'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(154) : error C2248: 'Grades::mFinal' : cannot access private member declared in class 'Grades'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(38) : see declaration of 'Grades::mFinal'
c:\documents and settings\my documents\visual studio 2005\projects\anotest\anotest\tazor.cpp(12) : see declaration of 'Grades'```

6. Originally Posted by selftest
i made the suggested alterations and overloaded my operators, but now the compiler is giving me errors having to deal with my functions' handling of private member variables.

Here is the code and erros

{

temp.mQuiz1 = Lhs.mQuiz1 - Rhs.mQuiz1;
temp.mQuiz2 = Lhs.mQuiz2 - Rhs.mQuiz2;
temp.mMidterm = Lhs.mMidterm - Rhs.mMidterm;
temp.mFinal = Lhs.mFinal - Rhs.mFinal;

return temp;
}
Your code is trying to access private member variables of the objects.
I propose you make access functions like Set/Get, which might be the usual approach. Otherwise you can make those member variables public (not recommended), or you can declare class Grades as a friend:
Code:
```class Grades
{
...
};```
It may be weird for a class to declare itself as a friend, but hey, it works. Since Grades is trying to work with itself, I believe it's safe to use friend here.
But you should always be careful in declaring friends. You can read up about them a little if you want to use them.

7. It may be weird for a class to declare itself as a friend, but hey, it works.
I disagree: a class declaring itself as a friend is meaningless.

From what I see, the solution is to declare operator- as a friend. A possibly better solution is to define operator-= as a member, then implement operator- in terms of operator-=.

8. Declaring the class as a friend of itself doesn't make sense. A class is already a friend of itself.

The problem is that your friend declarations for two of the operators don't match the definition of those operators. There is one small typo in the definitions of operator+ and operator-. Just fix the typo and you'll be good (except there are probably a couple other compiler errors to fix).

9. Consider a more refined approach to writing code which involves you compiling and testing a lot more often than you seem to be doing at present.

Getting dozens of error messages then dumping the whole mess on a forum for someone else to fix isn't a good strategy.

Especially since most of your errors seem to be of the 'cut-n-paste' variety, in that had you spotted the problem early enough, then none of the later errors would ever have appeared.

10. ^you are right my friend, in the future I will work harder to better analyze my code. I'd like to thank you all for the help once again.

11. Code:
```class Grades
{
...
...
};

...

{
...
}

{
...
}```
Those don't match, there's a subtle difference. This is the typo mentioned by Daved.

Also...
Code:
```int counter = 0;

Quiz1TotalAverage = Sum/counter;
Quiz2TotalAverage = Sumcounter;
FinalTotalAverage = Sum/counter;
MidtermTotalAverage = Sum/counter;```
You don't have an operator defined that divides a Grades object by an int. And Sumcounter is obviously a typo.

Last...
Code:
```while(!(Fin.eof()))
{
Fin >> Student;
Fout << Student;
...
}```
Don't do that. eof gets set after a failed attempt to read. After the last line of grades is read, eof will still be false which means you'll try to go through the loop one last time... which is not what you want. Prefer this:
Code:
```while( Fin >> Student )
{
Fout << Student;
...
}```

12. Originally Posted by Elysia
Your code is trying to access private member variables of the objects.
I propose you make access functions like Set/Get, which might be the usual approach.
There is no need to do that.
The problem comes from the definition not matching the befriended declaration (It's missing the ampersand.) Best to always start with a copy and paste of the declaration when writing the function definition.

13. Originally Posted by iMalc
There is no need to do that.
The problem comes from the definition not matching the befriended declaration (It's missing the ampersand.) Best to always start with a copy and paste of the declaration when writing the function definition.
Really, so you can access private members on const reference objects?

14. Really, so you can access private members on const reference objects?
Yes, if you are a friend function that does not modify those private member variables. selftest defined operator- to be such a function.

15. Yes, but I wasn't referring to friend functions (or classes).
In the above operator, whether or not the parameter were references and const or not, it is unable to do anything unless it's a friend.