Possible Duplicate:
Why do objects of the same class have access to each other’s private data?
Something I have never understood with trying to keep encapsulation:
Say I have a class called GameObject
, and a derived class called Human
. GameObject
has a private variable position
. I have multiple instances of Human
, I want each human to be able to call SetPos()
and set it's position as it wants. I do not however want one human to have the power to set up the position of another human. This is my problem.
If I have SetPos
public or protected, each human can alter each others positions, if SetPos()
is private, a human cannot even set its own position ( I need this, might be a weak example but I hope you understand).
Can anyone offer a solution?
Thanks.