#include <iostream>
usingnamespace std;
class b{
int x;
friendvoid setX(int);
friendint getX();
public:
friendvoid setX(int);
};
class a{
int x;
public:
friendvoid setX(int);
friendint getX();
intoperator+(b &obj);
};
int main(){
a obj_a;
b obj_b;
setX(5);
setX(10);
cout << "obj_a = " << getX() << endl;
cout << "obj_b = " << getX() << endl;
cout << "SUM of objects of different classes: " << obj_a + obj_b << endl;
return 0;
}
int a::operator+(b &obj){
return x + obj.x;
}
//This function serves for both classes, even it's not a member function of any class.
void setX(int value){
x = value;//Will generate an error.
}
int getX(){
return x;
}