In the early study of encapsulation, and of private members, the "get/set" pair is an introduction, but you'll find in professional code they do not appear frequently.
Encapsulation is more than merely privacy, but of operation of the internals.
Consider if every private member variable has a simple get and set function. Is the member actually private anymore? If the "set", in particular, allows what amounts to the unrestricted ability to modify the member variable, "privacy" is basically eliminated.
In my view where "get" and "set" are either the only or the primary functions associated with a member variable, it is a hint that perhaps privacy isn't even warranted, but is more generally an indicator that the "set" is being used by functions outside the class for a concept which should be a member function of the class.
Consider:
1 2 3
|
void setCustomer(vector<Customer> const &cust) {
customers = cust;
}
|
This proposes to copy a vector into customers. I'm not convinced this is a good thing to do.
The class is capable of starting with an empty container of customers, and subsequently accept customer information and append it to that list. "Set" functions don't usually apply to a container member in this fashion, because your proposed "add" function probably does all that is implied.
I note you have no "get" for the "customers" container, which is good because you have a "find" that would do the work likely to be the reason for "getting" that container.
Now this comes to the primary question about the streaming of a bank.
As you've discovered, where "customers" is private, the operator function is denied access to customers.
It is natural for students to react with an impulse to provide access to "customers" for the operator function, but it is an error to think so.
The bank has declared private ownership of "customers", and should be the sole proprietor of it. It is "Bank" that should copy the customers to the stream, and not the operator function.