Accessing a variable from one file , to another file
-
Hi All,
I'm stuck at a point.
I've a project myProject in which there custom libraries such as A,B,C,D,E.
So myProject contains myProject.pro , A,B,C,D,E
then the structure of A is A.pro , A1,A2,A3 where A1 has files like A1.pro, Headers(A11.h,A12.h,A13.h),Sources(A11.cpp,A12.cpp,A13.cpp)Same structure follows for B,C,D,E ....
a1 is a member variable[private] of class A11 [available in A11.h], how can I access it in file D12.cpp?
-
Hi,
Add proper accessors to your A11 class
-
@SGaist
and a1 is a private member of A11.
do you mean I've to follow inheritance? Is there any way other than inheritance and friend function? -
@SGaist
and a1 is a private member of A11.
do you mean I've to follow inheritance? Is there any way other than inheritance and friend function?@Swati777999 said in Accessing a variable from one file , to another file:
do you mean I've to follow inheritance?
No, @SGaist said "Add proper accessors to your A11 class". This means: add member functions to A11. It does not involve inheritance.
Do you know what is a "member function" or a "class method"?
-
@Swati777999 said in Accessing a variable from one file , to another file:
do you mean I've to follow inheritance?
No, @SGaist said "Add proper accessors to your A11 class". This means: add member functions to A11. It does not involve inheritance.
Do you know what is a "member function" or a "class method"?
@JKSH Yes, I am acquainted with the member functions but how to apply the logic here?
-
@JKSH Yes, I am acquainted with the member functions but how to apply the logic here?
@Swati777999 said in Accessing a variable from one file , to another file:
@JKSH Yes, I am acquainted with the member functions but how to apply the logic here?
Write member functions that allow other classes to access private member variables.
How do you usually use your member functions?