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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:49:31+00:00 2026-06-14T15:49:31+00:00

I have a problem with designing classes for my game which I create. In

  • 0

I have a problem with designing classes for my game which I create.

In my app, there is:

  • class CGame which contains all the information about game itself,
    e.g. screen width, screen height, etc. In the main() function I
    create a pointer to CGame instance.
  • class CGUIObject which includes fields specifying it’s position and
    draw() method, which should know how to draw an object according to
    screen size.
  • class CGUIManager which is a singleton and it includes a list of
    CGUIObject‘s. For each object in a list it just calls draw()
    method.

For clarity’s sake, I’ll put some simple code:

class CGame
{  
   int screenWidth;
   int screenHeight;
};

class CGUIObject
{
   CPoint position;
   void draw();     // this one needs to know what is a screen's width and height
};

class CGUIManager   // it's a singleton
{
   vector<CGUIObject*> guiObjects;
   void drawObjects();
};

And the main.cpp:

CGame* g;

int main()
{
   g = new CGame();

   while(1)
   {
      CGUIManager::Instance().drawObjects();
   }

   return 0;
}

Now the problem is, that each CGUIObject needs to know the screen size which is held by CGame, but I find it very dumb to include pointer to CGame instance in every object.

Could anyone, please, tell me what would be the best approach to achieve this?

  • 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-06-14T15:49:33+00:00Added an answer on June 14, 2026 at 3:49 pm

    Is there a reason that you are needing your screen resolution in your CGUIObject‘s?

    They have a position already, so if you have them draw themselves in local space, you can apply a transform to them in your CGUIManager in order to lay them out. You abstract your layout from the GUI objects themselves this way, and the objects don’t need to know which container they are living in (the screen, a window, a tab etc).

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

Sidebar

Related Questions

I have faced a problem while designing chess game. There are 2 Player: p1,
I'm designing a simple Connect 4 game. So far, I have 4 underlying classes:
I've recently encountered a problem designing a web page. I needed to have rounded
I'm re-designing a Web site and I have a problem with the existing data
When designing classes you usually have to decide between: providing a full constructor that
I am designing a template class Policy which needs to be able to handle
I'm currently learning Scala and I have some problems designing my case classes. I
I have three classes organized in following manner. Foo is a template class, Bar
I am currently struggling with a circular dependency problem when designing my classes. Ever
Problem : I have to create a number of tables for caching some amount

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.