I want to access a variable of one class into another class, and set it to some value, e.g. like in code here, i wanna set the some_flag
to true
in the secondClassFunction()
. Is it possible? If yes, how to do it?
Constraints due to system architecture:
- The two classes are not inheritable.
- The two classes are not related either.
- The function signatures of
secondClassFunction()
cannot be changed.
Here's the code snippet:-
#include <iostream>
using namespace std;
class FirstClass{
bool some_flag;
public:
void setFlag(bool flag);
bool getFlag();
};
FirstClass::FirstClass(){
some_flag(false);
}
class SecondClass{
public:
void secondClassFunction();
}
SecondClass::secondClassFunction(){
// do something here.
// I want to access some_flag using SecondClass object.
// how to do this?
}
int main() {
SecondClass secObj;
secObj.secondClassFunction();
return 0;
}
Will wrapper classes help? If yes, how?
EDIT:-
Constraint 4. Cannot make the classes friend functions.
Constraint 5. Cannot globalize the flag variable.
Details:-
The flag
is set in a function which is a member of FirstClass
.
I wish to reset this flag
in a function which is member of the SecondClass
.
The two classes are not related, inheritable, and their access specifiers cannot be changed, due to constraints of the system architecture.
The flag
is like a semaphore, it's used by multiple tasks, to denote the status of an activity, such as, whether the processor has received a certain command from a mobile app or not.