How is it that a pointer's object can access private members?

I noticed that in this lecture he binded the grab event to a private class function, He did pass in the grabber component to the object using it by using the keyword ‘this’, but it still strikes me as odd that by possessing an address to a class, you can modify its private members. Maybe i just dont fully understand whats going, but any decent explanation to sum up how this is possible?

Come to think of it he did also pass in the address of the private function, so maybe is it that by a member being private, it merely hides its address from other objects trying to access it?

@Steve1222, Can you put the relevent code?

Is this when you call the BindAction() function? Here, we merely pass what function to call the the Grab key is pressed. Since we pass a function to “this” class, it knows about itself.

In other words, BindAction delegates the call to something else, and that something else in this case is “this” instance of UGrabber. Since we are already inside UGrabber, it knows about Grab. If you were to call a function from a different class, you would get compile error saying the function is not accessible:

I also tried to pass the function to another instance of UGrabber, which compile correctly. Not sure it would run though.

Cheers,

Privacy & Terms