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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:32:56+00:00 2026-05-16T12:32:56+00:00

I wrote 2 classes, Agent and Timing . The third class will contain the

  • 0

I wrote 2 classes, Agent and Timing. The third class will contain the main() function and manage it all. The goal is to create n instances of Agent and a SINGLE instance of Timing. It’s important to mention that Agent uses Timing fields and Timing uses Agent functions.
How can I turn Timing to singleton?

//Agent.h
#ifndef Timing_h
#define Timing_h
#include <string>
#include "Timing.h"

class Agent{
    public:
        Agent(std::string agentName);
        void SetNextAgent(Agent* nextAgent);
        Agent* GetNextAgent();
        void SendMessage();
        void RecieveMessage(double val);
            //    static Timing runTime;

What I thought would solve my problem but I got:

‘Timing’ does not name a type

        ~Agent();

    private:
        std::string _agentName;
        double _pID;
        double _mID;
        Agent* _nextAgent;
};
#endif


//Timing.h
#ifndef Timing_h
#define Timing_h

class Timing{
    private:
        typedef struct Message{
            Agent* _agent;
            double _id;
        }Message;
        typedef Message* MessageP;

        Message** _messageArr;
        static int _messagesCount;

    public:
        Timing();
        void AddMessage(Agent* agent, double id);
        void LeaderElected(string name);
        void RunTillWinnerElected();
        ~Timing();
};
#endif

Is this really the way to create a singleton and if it is what is the problem?
And if not, how can I turn it to a singleton?

  • 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-16T12:32:57+00:00Added an answer on May 16, 2026 at 12:32 pm

    The most conventional way to create a singleton has following requirements:

    1) The constructor should be private and a static interface shall be provided which in turn creates a static object of the singleton class (which is a member of the class itself) and return it. Basically provide a global point of access.

    2) You have to decide in advance if you want the users of the class to be able to extend it and design your class to support it if required.

    If the above two requirements are met, there are a number of ways a singleton can be designed including the ones which would work with multi threaded applications.

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

Sidebar

Related Questions

I wrote the following class in javascript function main() { this.area ; this.$= function(target)
I want to redefine the ToString() function in one of my classes. I wrote
I wrote these two classes that simple encrypt and decrypt strings: Encode.php class Encode
I wrote the following classes to create a list view with custom list rows.
So I wrote two simple classes - X86StackFrame and X86CallStack: class X86StackFrame { public:
I have this header file, zeeheader.h, and I wrote some classes in it, I'm
I'm trying to write two classes, Sale and Register, for my OO class. Here
when we write all our application methods and variables in a classes is nothing
I am doing astrophysical research. I wrote a package containing the classes Star, Band,
I wrote a small class containing 2 class methods for some calculations. I call

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.