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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:08:19+00:00 2026-05-24T20:08:19+00:00

Here is what i am trying to do. I have Three Classes: 1) CEngine

  • 0

Here is what i am trying to do.

I have Three Classes:

1) CEngine

2) CLogManager

3) CWindowGL

Ad1.
This class ‘does’ the tricky things to get the game engine going,
an application utilizing it, can call only few public members to
get the game going –

class CEngine
{
  public:
   CEngine();
   ~CEngine();  // should this go to private?
    bool Init(width,height,...);
    void Destroy();
    void Run();
    bool LoadMap(...);
  private:
    CLogManager *m_pLogManager;    
    CWindowGL   *m_pWindowManager

}


// Example usage
CEngine *Engine=new CEngine;

Engine->Initialize(...)
Engine->LoadMap(...)
Engine->Run()
Engine->Destroy()
delete(Engine)

Ad2.
This class controls the logging facility
it just allows me to dump some log into the log data file:

class CLogManager
{
  public:
   CLogManager();
   ~CLogManager();
   void Write(const char *fmt,...);
  private:
   FILE *fp;
   std::string m_sFileName; // unique filename generated at the constructor
   SYSTEMTIME m_tSystemTime;

}

Ad3.
This class handles the window creation, and pixel format settings,
and few other things related to the window itself – nothing else,
but it also needs to utilize CLogManager – to dump few informations
for debug purposes.

Now the question is:

When a CLogManager constructor is called, class generates a unique filename that is:

m_sFileName="data/logs/enginelog_%i%i%i.txt"; // hour, minute, second

CEngine class in the Init method does:

m_pLogManager = new CLogManager;

and later on it uses it with m_pLogManager->Write(….) to log events.
That’s ok for CEngine, but i would like to use the same functionality
in CWindowGL class and here is the question.

I would like my code to share CLogManager across :

 CEngine
 CWindowGL
 ...
 ...
 ...

and few others that i’ll implement.

I can’t do this by adding “Instance()” type of method like:

   static CLogManager &Instance()
   {
    static CLogManager s_instance; 
    return s_instance;
   }

and calling:

CLogManager::Instance().Write(" LOG MESSAGE ");

As this would cause my CLogManager to generate new filename each time when a
constructor is called.

Do i have to

extern CEngine *Engine; 

somewhere to call

Engine->Log(" LOG MESSAGE ")

wrapper everytime or there is something else i can stick to?

I know it is more like a ‘code-design’ question, but i would like to see
how do you guys handle such things.

Normally i would do this with extern, but that would require me to check
m_pLogManager!=NULL within a wrapper function to a private member – and just
don’t know if that’s OK.

Maybe there’s some other – better approach?

I will be adding few other classes like. TexturesManager – and would like this class to
store the actual size of textures loaded and so on, so this would also require me to
not to call Instance() to class each time the texture is called – as this would create/destruct the class without storing the needed size / array of textures already loaded…

Uff..

Thanks, hope this is clear.

  • 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-24T20:08:21+00:00Added an answer on May 24, 2026 at 8:08 pm

    I can’t do this by adding “Instance()” type of method as this would cause my CLogManager to generate new filename each time when a constructor is called.

    Actually no, the constructor would be called only once during your program lifetime. The singleton pattern is what you most likely want for your logging class.

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

Sidebar

Related Questions

I have three classes like this. class A { public class innerB { //Do
Here is my custom class that I have that represents a triangle. I'm trying
I have a data object which has a base class with three derived classes,
I have the following headache… I'm trying to get the average rating for three
Trying to get past a class cast exception here: FooClass fooClass = (FooClass )
Here's what I'm trying to do : I have an entity Task with a
Here is a problem I am trying to solve: I have an irregular shape.
here's what I'm trying to do : On a page, I would have a
Here is what I am trying to do. I have a block of text
Here's what I'm trying to do. I have an ASP.NET MVC web application, where

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.