static global object
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: static global object

  1. #1
    Join Date
    Jul 2007

    Red face static global object

    I was going through one URL on Singleton.

    Some lines from the URL confused me as below
    What problem does this solve, or put another way, what is our motivation to use it? In nearly every application, there is a need to have an area from which to globally access and maintain some type of data. There are also cases in object-oriented (OO) systems where there should be only one class, or a predefined number of instances of a class, running at any given time. For example, when a class is being used to maintain an incremental counter, the simple counter class needs to keep track of an integer value that is being used in multiple areas of an application. The class needs to be able to increment this counter as well as return the current value. For this situation, the desired class behavior would be to have exactly one instance of a class that maintains the integer and nothing more.

    At first glance, one might be tempted to create an instance of a counter class as a just a static global variable. This is a common technique but really only solves part of the problem; it solves the problem of global accessibility, but does nothing to ensure that there is only one instance of the class running at any given time.
    My doubt is at this point: but does nothing to ensure that there is only one instance of the class running at any given time.

    As per my consideration if it is static global variable then at all the time only one instance will be running at any time.

    Please clarify

  2. #2
    Join Date
    Jan 2006

    Re: static global object

    Not quite: the static global variable will be one instance of the class, but maybe by accident or mistaken intention one might create another instance of the class other than that static global variable.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Jul 2007

    Re: static global object

    Thanks for the quick response. Laserlight

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)