I am a beginner in C++.
I want to know how can we access data member of a class from another class. I am facing problem in visualizing the things in writing separate .h and .cpp file.
Here I explain the things.We have three classes.
In a.cpp (assuming the a.h files is wriiten )
void A:: fun_a()
cout<<"Value in A:"<<ii<<endl;
// suppose both the functions are called and the value of ii is 5 and jj is 2
cout<<"value in A:" << ii <<"value in B:" <<jj;
//Now I want to access the data ii from and jj from the C class.
//I want to assign kk a member of C class or a simple variable the value of ii (i.e. 5).
How to go about it ?
If declare a member of type B in our C class..it will carete another instance of B but does not contains the data in the live B object.
Is passing a reference to the B class in the contructor of C class is asolution? If so, whow to do that. I am getting confused in implementin this concept.
And what other ways are there?
Thanks and regards,
Back to Top