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

  • SEARCH
  • Home
  • 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 737969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:46:58+00:00 2026-05-14T07:46:58+00:00

Hi! I have a working prototype of a game engine and right now I’m

  • 0

Hi!

I have a working prototype of a game engine and right now I’m doing some refactoring.
What I’m asking for is your opinion on usage of the following C++ coding patterns.

I have implemented some trivial algorithms for collision detection and they are implemented the following way:

Not shown here – class constructor is made private and using algorithms looks like Algorithm::HandleInnerCollision(...)

class Algorithm {
   // Private routines
   static bool is_inside(Point& p, Object& object) {
      // (...)
   }

   public:
      /**
       * Handle collision where the moving object should be always
       * located inside the static object
       *
       * @param  MovingObject & mobject  
       * @param  const StaticObject & sobject  
       * @return void
       * @see
       */
      static void HandleInnerCollision(MovingObject& mobject, const StaticObject& sobject) {
         // (...)
      }

So, my question is – somebody advised me to do it “the C++” way – so that all functions are wrapped in a namespace, but not in a class. Is there some good way to preserve privating if I will wrap them into a namespace as adviced?

What I want to have is a simple interface and ability to call functions as Algorithm::HandleInnerCollision(...) while not polluting the namespace with other functions such as is_inside(...)

Of, if you can advise any alternative design pattern for such kind of logics, I would really appreciate that…

  • 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-14T07:46:59+00:00Added an answer on May 14, 2026 at 7:46 am

    If the various functions have something to do with each other, if it’s more than helping but really have a common factor such as acting on the same entity, then put them in a class. On the other hand, if a function acts on the same entity as others, but you also want to reuse it for other entities that are convertible to the first entity then extract it outside of the class:

    bool same_size(const shape& a, const shape& b)
    {
        return a.bounding_x == b.bounding_x && a.bounding_y == b.bounding_y;
    }
    

    The above function will work with any two objects that are convertible to or descend from shape.

    Put functionality that you don’t want to share with other translation units (i.e. helper functions and help objects) in an unnamed namespace. This is the C++ equivalent of the C static functions, and it instructs the compiler to keep anything inside the unnamed namespace private to this translation unit.

    namespace {
    bool is_inside(Point& p, Object& object)
    {
        // ...
    }
    // ...
    }
    

    Put all the functionality that you want to share with other translation units in a named namespace. This will instruct the compiler to wrap the code with a common name, so names don’t collide with external code (libraries etc.) names.

    namespace kotti {
    void HandleInnerCollision(MovingObject& mobject,
                              const StaticObject& sobject)
    {
        // ...
    }
    
    // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on game engine prototype and have the following question: Right now
I'm working on a prototype for a shmup game in C++ using SDL...Right now
Here's the thing, I now have a working prototype of what I want and
I have a simple code fragment in JS working with prototype inheritance. function object(o)
I have been working on a Windows Mobile app for a little while now
I am making a DOM builder which I have working succesfully but now I
I have a working prototype of a Java application that is using Apache Commons
I have been working on a prototype site using a mamp server and the
I am working on a game engine in C++ using Lua to define NPCs.
I was building something, it was a working prototype but had glitches and now

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.