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'.
#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");
}
Last edited by MarauderIIC on Sun Oct 28, 2012 5:33 pm, edited 2 times in total.
Reason:I put in the code tags for you. Use them yourself in the future =)