Is it alright to have a function that is not a part of any specific class when using an object-oriented approach. In my case, I would like to have a check_collision() function that takes two SDL_Rects as arguments and then returns a true or false. The SDL_Rects would be found inside existing objects like a character class or a tile class. Is there a good place to put this function? Am I overlooking a better approach to this problem?
Is it alright to have a function that is not a part of any
Share
I will post up the only dissenting answer (for now). Since you have an already existing type (
SDL_Rect) that you don’t own (its included from a 3rd party), I would suggest to implement this as a free function as you have suggested in your original answer. In my opinoin, this will be the cleanest approach for your direct question.Your other option is to write a class that wraps
SDL_Rectand provides collision detection, like this:But that seems like overkill for this particular case.
If you already had a
DisplayableObjectclass that all displayable objects derived from I may be swayed to suggest adding this as a member, but that doesn’t appear to be the case.