Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6895271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:53:15+00:00 2026-05-27T06:53:15+00:00

Is it alright to have a function that is not a part of any

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:53:15+00:00Added an answer on May 27, 2026 at 6:53 am

    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.

    bool check_collision(const SDL_Rect& l, const SDL_Rect& r);
    

    Your other option is to write a class that wraps SDL_Rect and provides collision detection, like this:

    class CD_SDL_Rect
    {
    public:
        bool check_collision(const SDL_Rect& r);
    private:
        SDL_Rect r_;
    };
    

    But that seems like overkill for this particular case.

    If you already had a DisplayableObject class 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, so I have a button that when clicked, will change the class of
Alright, I'm confused as hell. I have an object that I store in a
I have created a VB.NET 2008 Class Library that has, for the most part,
I have a WordPress site that I am using a gravity form. I would
Alright have been working to switch to jQuery 1.7's new and improved .on() function
Alright so I have a task, that I have to let the client try
Alright, probably not the best title, but meh. I have the following code inside
Alright here's the situation, I have an application written in the Zend_Framework, that is
I have a C# console app that I would like to keep running, even
I would like to do a function that manipulates a vector in order to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.