#include "MyClass.h"
#include <iostream>
using std::endl;
using std::cout;
void Helper(MyClass* object, bool MyClass::*pointer);
int main() {
MyClass NewObject;
MyClass* pointer = &NewObject;
bool MyClass::*ptr = &MyClass::tip3; //tip3 is inaccesable
Helper(pointer, ptr);
return 0;
}
void Helper(MyClass* object, bool MyClass::*pointer) {
if(object->*pointer == true) {
cout << "now is false" << endl;
object->*pointer = false;
}
else
cout << "it was not true" << endl;
return;
}
so this code works only if members are public,
I dont know how to make this code work now when mebers are private.
I have tried to use member function which will return address of member but that does not work.
Private members are only visible from their classes, so the code works as expected. You can make them visible or create get functions in MyClass in order to acces its values:
the thing which I'm trying to learn is using poiner to class meber in this format: bool MyClass::*ptr = &MyClass::tip3; this works for public members
a task from my book is asking me to create the same thing for private members..
that's the main problem.
I cant find any article on the net on how to do that(using this format) MyClass* pointer = &NewObject; and this is the first argument of the function which works.
and this function should use that pointer: (that's why I need such pointer type)