To provide potentially more information about what you may be trying to do, see the following example:
class var1
{
int a, b;
public:
var1 operator+( const var1& rhs )
{
var1 output;
output.a = this->a + rhs.a;
output.b = this->b + rhs.b;
return output;
}
};
class var2
{
var1 res1, res2;
public:
var2 operator+( const var2& rhs )
{
var2 output;
output.res1 = this->res1 + rhs.res1;
output.res2 = this->res2 + rhs.res2;
return output;
}
};
This is not overloading, but based on your code it seems like this might be what you are trying to accomplish. If you add more detail to your question I can better tailor this answer to your needs.
To explain this example, because the addition operator is defined in var1 it can be used to sum the respective fields of var2. By defining your own addition operator on var2 you can use the operator your defined in var1 to perform a logical summation of parts and return the result. This is not overloading or overriding anything, because the two classes have no relationship to each other.
For more information on operator overloading in C++, read this on SO.
1
solved Operator Overloading of one class to be used in another class [closed]