Re: Single instance issue



On Dec 22, 10:57 am, Sarath <CSar...@xxxxxxxxx> wrote:
On Dec 21, 10:14 pm, Abhishek Padmanabh <abhishek.padman...@xxxxxxxxx>
wrote:





On Dec 21, 11:35 am, Sarath <CSar...@xxxxxxxxx> wrote:

I've to write a single instance class. there are different methods to
control the single instance of a program

class CSingleton
{
public:
    CSingleton& GetInstance(){ static CSingleton s; return s; }

private:
    CSingleton(){}
    ~CSingleton(){}

}

The above code failed to compile in Visual C++ 6.0 but compiled in
Visual C++ 7.1 and Visual C++ Express 2008. CRT calling the destructor
of the class. So that Visual C++ 6.0 compilation error is correct
according to the concept.

I also tried in Dev C++. It was successful but didn't call the dtor of
the class. Which implementation is correct according to the standard.

How do you know it did not call the destructor?- Hide quoted text -

- Show quoted text -

I Just put some string inside dtor and executed

If it were a static object, the destructor must be called! I checked
with g++ 3.4.4 (that comes with cygwin) and it does call the
destructor. The only case when it should not is when you allocate on
free store and don't destroy the object.

As for VC 6, if you can't move away from it, then consider making the
destructor public. That should do the trick.
.



Relevant Pages