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 7191355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:42:41+00:00 2026-05-28T19:42:41+00:00

I have an object of class Level that has several subsystems (child objects) it

  • 0

I have an object of class Level that has several subsystems (child objects) it uses to manage its state (e.g. EntityManager, InputManager, Physics). I want to expose some of the methods of those subsystems in the external interface of Level.

Here is one solution:

uint32_t Level::CreateEntity()
{
    return entityManager.CreateEntity();
}

Entity& Level::GetEntity(uint32_t entityId)
{
    return entityManager.GetEntity(entityId);
}

uint16_t Level::CreateInputState()
{
    return inputManager.CreateInputState();
}

void Level::AttachInputState(uint32_t entityId, uint16_t inputStateId)
{
    inputManager.AttachInputState(entityId, inputStateId);
}

InputState& Level::GetInputState(uint16_t inputStateId)
{
    return inputManager.GetInputState(inputStateId);
}

This solution requires me to duplicate the method declarations inside the Level class and write one-line calls that redirect the control to the subsystem. In projects I have worked on in the past, this has been troublesome to manage.

Another solution is to expose the subsystems in the public interface. Preferably this can be avoided since it’s not important to objects outside of Level which subsystem the calls get forwarded to.

Is there a design that could more elegantly handle 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-28T19:42:42+00:00Added an answer on May 28, 2026 at 7:42 pm

    As requested by the OP I will post a solution that I suggested in the comments.
    I am fairly sure, that there is a better one with templates in the new C++ standard but anyway I will post the preprocessor solution which is ugly and should not be used!

    #define FUNCTION_DECLARATION(RETURNTYPE, FUNCTIONNAME, ...) \
         RETURNTYPE FUNCTIONNAME(__VA_ARGS__)
    

    This would be used in the class declaration as:

    class Level {
        FUNCTION_DECLARATION(uint32_t, CreateEntity);
        FUNCTION_DECLARATION(Entity&, GetEntity, uint32_t);
    };
    

    The definition would look like:

    #define FUNCTION_DEFINITION(RETURNTYPE, PROPERTY, FUNCTIONNAME, ...) \
        RETURNTYPE Level::FUNCTIONNAME(__VA_ARGS__) \
        { \
            return PROPERTY.FUNCTIONNAME(__VA_ARGS__); \
        } \
    

    And now the very ugly usage to make this work:

    FUNCTION_DEFINITION(Entity&, entityManager, GetEntity, uint32_t(entityId))
    

    I can not guarantee that this will work for any type also I have not tested most of the code. As you can see this “hack” with the input will only work for plain types and not references or pointers. On classes it will trigger the copy constructor!

    Of course this can be improved by replacing the VA_ARGS with a variable for the type and the variablename for each argument of the function but again this is very tedious and one would have to write a template for each number of arguments that should be used. This will in result yield nearly as much code as before.

    So let me state again: Stick with templates they are by far better than this!
    It is just that I do not know how to do it with them. So please if there is anyone out there who knows how to do it with templates, instead of bashing me for this ** code write the beautiful solution everyone here is aching for.

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

Sidebar

Related Questions

I have a controller that has many actions and it specifies a default class-level
I have an object class called BOM. It has a method, getChildItem() which returns
I'm working on an iPhone application. I have an object of class Row that
We have the Class object (an object that reference a Class) so you can
My program has a class with a vector of Level objects named levels .
I have a data object which has a base class with three derived classes,
I created a custom object that has a Bitmap field. I'm drawing several of
I have a class MyClass that has a static variable. Class implements smth like
I have a situation where I need to access an object that has been
I'm making Braid. I have a class Wall that prevents that an object goes

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.