Hi banfa,
I'm glad by your solution....
Can you elaborate about what you have written the code above...
Also I have done some modifications in your program....
Can you explain me the difference...
I'm confused by the term friend and needs to clear about that
- class A;
-
-
class B
-
{
-
public:
-
B();
-
static friend void setValue(int val);
-
static A* pa;
-
};
-
-
class A
-
{
-
static friend void setValue(int val);
-
int ia;
-
public:
-
A():ia(0){}
-
void display()
-
{
-
cout<<"Data:"<<ia<<endl;
-
}
-
};
-
-
B::B()
-
{
-
pa = new A;
-
}
-
-
A* B::pa = 0;
-
-
void setValue(int val)
-
{
-
B b;
-
b.pa->ia = val;
-
}
-
-
int main(int argc, char** argv[])
-
{
-
B b;
-
setValue(5);
-
B::pa->display();
-
return 0;
-
}
Eagerly Waiting for your reply