Friend Class Issues
Posted: Thu Oct 25, 2012 6:19 pm
Thanks to everyone reading this, and please help! I'm trying to get it so that the value of an inherited variable in a friend class will change, but it only seems to stay the same. Below I have posted the code. I expected to get the output '1''2', but instead it's like I never added 1 to x and instead got the output '1''1'.
Code: Select all
#include <iostream>
using namespace std;
class Me {
private: int X;
public:
Me::Me();
void add();
friend class You;
};
class You {
public:
Me m;
void show();
};
Me::Me(){
X = 1;
}
void You::show(){
cout << "The number is " << m.X << endl;
}
void Me::add(){
X+=1;
}
int main(){
Me m;
You y;
y.show();
m.add();
y.show();
system ("pause");
}