If you must expose personal data from one class to another, than make the second class a friend. Creating an accessor for your personal data is striking to make it private in the first place. The principle of single responsibility is not relevant to this.
Edit
In response to Dimaβs comment below, I may have thought too much when I said βgoalβ. After all, there are several reasons why private data members are private. One of the reasons, according to Dima, is to protect the integrity of the object. Accessories really achieve this.
But the second (and, more importantly, in my opinion) reason is to hide the details of the class implementation. After you added public accessors, you lost control over how many other classes reference the implementation details of the class. Over time, this can make it difficult to change your implementation due to the cascading effect for other classes.
Classes of friends, although far from ideal, at least give you tight control over how many classes your changes will affect. Another advantage is that when you make changes, you know exactly which classes may be affected. So this is the best option when you should share your inner classes. But the best option for everyone (of course) is not to not disclose implementation details at all.
source share