Well, you already have a public get() function to retrieve num, so you don't need direct access to the private members of MyClass. And, it seems to me that making class Pred a public member of MyClass creates a hole in MyClass's encapsulation: now anyone can create an object of type Pred and they will gain direct access to the private members of MyClass. That allows them to bypass the interface you defined for MyClass, namely your setNum() and setChar() functions.Quote:
It gives it access to private members and encapsulates it as part of MyClass?
In this case, that doesn't really mean much since your set() functions allow you to assign any values to the members num and ch, but what if your set() functions were defined such that you could only assign non-zero integers to num and only lower case chars to ch? In that case, someone could create a Pred object and use it to assign negative integers to num and assign upper case chars to ch. So, in principle I think having class Pred as a public member of class MyClass is a bad idea.