Original Post
Hello, this is actually my first post on the forums. Regarding the topic: is using the friend keyword considered bad OOP style? I heard that some people refer to it as hack, others say that isn't bad at all. The reason I ask is because I tend to use this keyword frequently. Currently I am working on a physics engine and I have this class that holds an array of all the rigid bodies, contacts, joints etc in the simulation. The bodies, contacts etc are classes themselves and have a lot of members that I don't want to make publicly accesible. But with regards to the actual simulation, I need access to these private members from within the main world-class, thus I used the friend keyword. But I am not too sure whether this is good coding practice or not. Another option would have been either writing a lot of get/set routines, or to shift things around, like giving the Body-class the method for detecting collisions, but this would require, that the body class had access to the contacts class' private members... So the decision to use the friend keyword seemed pretty sensible to me. What do you guys think? Is it ok to use the friend keyword in this case and also in general?