Hello. I am trying to write a function (setxy in class A) in one class to access members (function sety in class B) of another class. I am not sure what is wrong with my code. Please help.
#include <iostream>
usingnamespace std;
class A {
public:
int x;
public:
A() { x = 0;}
void setxy(B & obj)
{
obj.sety();
}
};
class B {
public:
int y;
void sety(){
y=0;
cout<<y<<endl;}};
int main(){
A obja;
B objb;
obja.setxy(objb);
return 0;
}
#include <iostream>
usingnamespace std;
class B
{
public:
int y;
void sety()
{
y=0;
cout << y << endl;
}
};
class A
{
private: //
int x;
public:
A() { x = 0;}
void setxy(B & obj)
{
obj.sety();
}
};
int main(){
A obja;
B objb;
obja.setxy(objb);
return 0;
}