473,408 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Singleton Class

Hi,

I am using a singleton class like the one given below:

class singleton
{
static singleton *object;
singleton();

public:
getInstance();
~singleton();
};
From some other function i try to do the following:

singleton *p= singleton :: getInstance();
detele p;
But here my program dumps. What could be the problem.

Thanks and Regards,
Saurabh

Jan 9 '06 #1
5 1825
Kumar Saurabh wrote:
Hi,

I am using a singleton class like the one given below:

class singleton
{
static singleton *object; // Where is the singleton allocated? singleton();

public:
getInstance();
// What does this return?
~singleton();
};
From some other function i try to do the following:

singleton *p= singleton :: getInstance();
detele p;
The singleton object should deal with it's own lifetime, why are you
trying to delete it?
But here my program dumps. What could be the problem.


I think you need to re-read that chapter of your book, or get a better book.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Jan 9 '06 #2
Kumar Saurabh wrote:
Hi,

I am using a singleton class like the one given below:

class singleton
{
static singleton *object;
singleton();

public:
getInstance();
~singleton();
};
From some other function i try to do the following:

singleton *p= singleton :: getInstance();
detele p;
But here my program dumps. What could be the problem.


That depends on the implementation the getInstance() function.

Jan 9 '06 #3

"Kumar Saurabh" <ku***********@motorola.com> wrote in message
news:43**************@motorola.com...
Hi,

I am using a singleton class like the one given below:

class singleton
{
static singleton *object;
singleton();

public:
getInstance();
~singleton();
};
From some other function i try to do the following:

singleton *p= singleton :: getInstance();
detele p;
But here my program dumps. What could be the problem.

Thanks and Regards,
Saurabh


If you program craps out deleting p, then p is bad, either its not
initialized
or you've already deleted it or perhaps its pointing to something which is
not allocated ( like a static object ). Post the entire listing of your
code.

Jan 10 '06 #4
Kumar Saurabh wrote:
Hi,

I am using a singleton class like the one given below:

class singleton
{
static singleton *object;
singleton();

public:
getInstance();
~singleton();
};
From some other function i try to do the following:

singleton *p= singleton :: getInstance();
detele p;
But here my program dumps. What could be the problem.

Thanks and Regards,
Saurabh


Could we have the code please ? Did you intialise object ? Remember it
is static and you need to intialise/allocate it outside your class
declaration.

Jan 10 '06 #5
it would be nice if you can get us the code .. Have gdb running on your
executable it would tell you how it is happening ..(PRINT p's address
every time )

Jan 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Uwe Mayer | last post by:
Hi, I've been looking into ways of creating singleton objects. With Python2.3 I usually used a module-level variable and a factory function to implement singleton objects. With Python2.4 I...
7
by: Tim Clacy | last post by:
Is there such a thing as a Singleton template that actually saves programming effort? Is it possible to actually use a template to make an arbitrary class a singleton without having to: a)...
10
by: E. Robert Tisdale | last post by:
Could somebody please help me with the definition of a singleton? > cat singleton.cc class { private: // representation int A; int B; public: //functions
1
by: Jim Strathmeyer | last post by:
So I'm trying to implement a singleton template class, but I'm getting a confusing 'undefined reference' when it tries to link. Here's the code and g++'s output. Any help? // singleton.h ...
3
by: Alicia Roberts | last post by:
Hello everyone, I have been researching the Singleton Pattern. Since the singleton pattern uses a private constructor which in turn reduces extendability, if you make the Singleton Polymorphic...
5
by: Pelle Beckman | last post by:
Hi, I've done some progress in writing a rather simple singleton template. However, I need a smart way to pass constructor arguments via the template. I've been suggested reading "Modern C++...
12
by: Preets | last post by:
Can anyone explain to me the exact use of private constructors in c++ ?
5
by: tobias.sturn | last post by:
Hi! I have written this template for making a singleton: #define DECLARE_SINGLETON(classname) \ private: \ static classname* m_pThis; \ classname(); \ class Guard \ { \ public: \
3
weaknessforcats
by: weaknessforcats | last post by:
Design Pattern: The Singleton Overview Use the Singleton Design Pattern when you want to have only one instance of a class. This single instance must have a single global point of access. That...
3
by: stevewilliams2004 | last post by:
I am attempting to create a singleton, and was wondering if someone could give me a sanity check on the design - does it accomplish my constraints, and/or am I over complicating things. My design...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.