bugPingus - Bugs: bug #1613, Classes with only one instance

 
 

bug #1613: Classes with only one instance

Submitted by:  Henri Manson <hfmanson>
Submitted on:  Tue 05 Nov 2002 02:00:14 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: None
Open/Closed: ClosedRelease: SVN
Operating System: AllPlanned Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Tue 05 Nov 2002 02:00:14 AM UTC, original submission:

I have the following proposal to change classes with only one instance e.g. ScreenManager as follows (an example):

class InstanceClass
{
public:
int x;
int y;

static InstanceClass instance;

InstanceClass() : x(3), y(4) { }
~InstanceClass()
{
printf("cleaning up\n");
}
};

InstanceClass InstanceClass::instance;

int main(int argc, char* argv[])
{
printf("%d %d \n", InstanceClass::instance.x, InstanceClass::instance.y);
return 0;
}

The advantages are:
- No more need to implement init/deinit functions: the object is automatically destroyed at program exit
- A direct object -> (slightly) better performance

I'm very curious what your opinion is.
This compiles under gcc and VC++

Henri Manson <hfmanson>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by grumbel (Updated the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 10 Aug 2007 04:30:57 AM UTCgrumbelOpen/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1