Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Single instance

Reply
Thread Tools

Single instance

 
 
ccs
Guest
Posts: n/a
 
      06-06-2004
class csingle
{
public:
static csingle membs;
int n1, n2, n3;
csingle(int v1, int v2, int v3)
{
...
}
....
};

csingle csingle::membs(5, 7, 13);

Is there anything wrong with the code for creating a single instance of
csingle?

How to get the address of the object "csingle::membs"?


 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      06-06-2004
ccs wrote:

> class csingle
> {
> public:
> static csingle membs;
> int n1, n2, n3;
> csingle(int v1, int v2, int v3)
> {
> ...
> }
> ...
> };
>
> csingle csingle::membs(5, 7, 13);
>
> Is there anything wrong with the code for creating a single instance of
> csingle?


Look up the Singleton Pattern in the book /Design Patterns/. Then don't
abuse it.

You have reinvented much of it, but there's one small problem with your
code. If you use csingle::membs before main() calls, (such as from the
constructor of another global object in another translation unit
["module"]), you might accidentally access that object before it constructs.

> How to get the address of the object "csingle::membs"?


Uh, &csingle::membs?

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Taglib problems - instead of a single instance per page, I have a single instance per application. chris brat Java 1 05-10-2006 11:16 AM
Problem when subclass instance changes base class instance variable Gerry Sutton Python 1 04-16-2005 06:06 AM
Accessing an instance via its memory address (instance at ...) Kent Johnson Python 4 11-13-2004 07:42 PM
converting base class instance to derived class instance Sridhar R Python 14 02-10-2004 02:47 PM
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. DJ Dev ASP .Net 3 02-08-2004 04:19 PM



Advertisments