-
MoseHasLikes 0Problem Description
Hi there.
Sorry I have to ask this stupid question.
How could I access a boolean variable, which is in class A, at class B?
This is a stupid easy question but bothers me so much. Hope you can answer for me.
/* * #### This is file "A.h" */ Class A { public: bool abool; }
/* * #### This is file B.cpp */ #include "A.h" bool init() { bool B_bool=A::abool; A::abool = false; return true; }
Something like that.
Thank you.
-
MoseHasLikes 0
After hours struggling, I realized that I am actually a fool.
I am going to change my question.
How do I set a global variable(boolean) for multiple class to access?
//global scope bool globalBool = false;
//classA.h class A { public: bool init(){boolA = globalBool;}; private: bool boolA; }
//classB.h class B { public: bool init(){boolB = true; globalBool = boolB;}; private: bool boolB; }
Something like that.
-
MoseHasLikes 0
I have used a pretty tricky way to do this.
I use UserDefault to save this boolean so that I can access it wherever I want.
-
barabasandras1Likes 0
Create a Globals.h where you define all your global/public variables you want to reach no matter where you are.
This reply has been verified.
-
MoseHasLikes 0
Sounds like another good way. Thanks!
Login to reply