Connecting Tech Pros Worldwide Help | Site Map

question on instances

  #1  
Old July 22nd, 2005, 09:59 AM
Alan Lee
Guest
 
Posts: n/a
Hi, I am wondering if there is a way to create a class where only one
predefined instance is allowed. I am just trying to find a way to create a
global variable with its own member functions whhich would be accessible by
all other classes. I could just follow the normal class thing but I'm
wondering if there is a better way to do it.thanks .


  #2  
Old July 22nd, 2005, 09:59 AM
Pete
Guest
 
Posts: n/a

re: question on instances


Alan Lee wrote:[color=blue]
> Hi, I am wondering if there is a way to create a class where only one
> predefined instance is allowed. I am just trying to find a way to
> create a global variable with its own member functions whhich would
> be accessible by all other classes. I could just follow the normal
> class thing but I'm wondering if there is a better way to do
> it.thanks .[/color]

Google for the "Singleton pattern", or put your data and functions into a
namespace.

- Pete


  #3  
Old July 22nd, 2005, 09:59 AM
Pete
Guest
 
Posts: n/a

re: question on instances


Alan Lee wrote:[color=blue]
> Hi, I am wondering if there is a way to create a class where only one
> predefined instance is allowed. I am just trying to find a way to
> create a global variable with its own member functions whhich would
> be accessible by all other classes. I could just follow the normal
> class thing but I'm wondering if there is a better way to do
> it.thanks .[/color]

Google for the "Singleton pattern", or put your data and functions into a
namespace.

- Pete


  #4  
Old July 22nd, 2005, 10:00 AM
jeffc
Guest
 
Posts: n/a

re: question on instances



"Alan Lee" <alanlee@stanford.edu> wrote in message
news:c4sb6f$9rh$1@news.Stanford.EDU...[color=blue]
> Hi, I am wondering if there is a way to create a class where only one
> predefined instance is allowed. I am just trying to find a way to create[/color]
a[color=blue]
> global variable with its own member functions whhich would be accessible[/color]
by[color=blue]
> all other classes. I could just follow the normal class thing but I'm
> wondering if there is a better way to do it.thanks .[/color]

Search the web for the "singleton" pattern. Typically, you must make the
constructor private or protected, and then provide a static function that
users can call to get a new object. It will only allow 1 object to exist at
a time.


  #5  
Old July 22nd, 2005, 10:00 AM
jeffc
Guest
 
Posts: n/a

re: question on instances



"Alan Lee" <alanlee@stanford.edu> wrote in message
news:c4sb6f$9rh$1@news.Stanford.EDU...[color=blue]
> Hi, I am wondering if there is a way to create a class where only one
> predefined instance is allowed. I am just trying to find a way to create[/color]
a[color=blue]
> global variable with its own member functions whhich would be accessible[/color]
by[color=blue]
> all other classes. I could just follow the normal class thing but I'm
> wondering if there is a better way to do it.thanks .[/color]

Search the web for the "singleton" pattern. Typically, you must make the
constructor private or protected, and then provide a static function that
users can call to get a new object. It will only allow 1 object to exist at
a time.


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on Data Access Application Block (DAAB) stephen answers 2 August 5th, 2006 02:55 AM
concurrency question on HttpApplication,HttpModule, and Page walter answers 2 April 25th, 2006 08:25 PM
question on instances Alan Lee answers 4 July 22nd, 2005 09:30 AM
Question on Standard Types hostmaster answers 4 July 18th, 2005 03:21 AM