Base Class
#include <rw/pointer/RWTSingleton.h>
Ensures that a class has only one instance, and provides a global point of access to it. This is an Object Creational pattern. For more information, see Design Patterns, by Gamma, Helm, Johnson, and Vlissides.
#include <rw/pointer/RWTSingleton.h> #include <iostream.h> class Foo { public: function(){cout << "I'm a foo example" << endl;}; }; RWTCountingPointer<Foo> singleFooPtr = RWTSingleton<Foo>::instance(); int main(void) { singleFooPtr->function(); return 0; }
RWTSingleton(void);
The constructor is protected to ensure that only one instance can ever get created.
static RWTCountingPointer<T, RWSafeCounter>& instance(void);
Creates and returns the instance of T, if it has not already been created.
static RWTCountingPointer<T, RWSafeCounter> & get(void);
Protected acessor function that gives access to the class state. Inherited classes use this function.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.