Is it possible to overload operator of class A in a friend class B? : <p>I'm trying to solve the following problem from the lab where it says:</p>

<blockquote>
  <p>Define a class called Repository that has 2 integer private variables. The >class contains an empty constructor and another one with 2 parameters. An >accesor method that displays the variables values is also included in the >class. Write another class called Mathematics which is friend to the first >one. This class contains the implementation of the elementary arithmetical >operations (+, -, *, /) applied to the values stored in the first class. Each >arithmetical method receives as parameter an object instantiated from the >first class.</p>
</blockquote>

<p>I have been searching all over the internet for a couple of hours already but I haven't found anything about overloading operators of a class in another one. I understand the overloading mechanism, I solved the problem using friend functions but I'm still asking myself if it is possible to do as above mentioned and if yes, I wish to know how to do it. Thanks in advance !</p>

<p>I have tried the solution mentioned <a href="https://stackoverflow.com/questions/3981911/operators-overloading-in-other-classes">here</a></p>

<pre><code>//friend Repository operator + (Repository &amp;, Repository &amp;);
    friend Mathematics;
};
/*
Repository operator + (Repository &amp;rep1, Repository &amp;rep2)
{
    Repository obToRet;
    obToRet.val1 = rep1.val1 + rep2.val1;
    obToRet.val2 = rep1.val2 + rep2.val2;
    return obToRet;
}*/

class Mathematics
{
public:
    friend Repository;
    public static Repository operator+(Repository &amp;rep1, Repository &amp;rep2)
    {
        Repository objtoret;
        objtoret.val1 = rep1.val1 + rep2.val1;
        objtoret.val2 = rep1.val2 + rep2.val2;
        return objtoret;
    }
};
</code></pre>
