0
Don't you think friend function makes private member vulnerable towards data security?
As friend function can access private members of a class I think data security is compromised somewhere. What is the use of friend function?
1 Odpowiedź
+ 1
It does, that's one reason why many people don't recommend using it. Also, if your friend function accesses private members, that function will depend on the implementation of your class. This means that if you change the implementation of the class, you may have to change the friend function as well. It's recommended to use getters and setters instead of exposing private variables to friend functions. This way other parts of the code will only see the interface and the underlying implementation can change without having to worry about it.