On Dec 21, 5:41 pm, Salt_Peter <pj_h...@yahoo.com> wrote:
On Dec 21, 3:11 am, Sarath <CSar...@gmail.com> wrote:
On Dec 21, 4:49 pm, Ian Collins <ian-n...@hotmail.com> wrote:
Sarath wrote:
I've to write a single instance class. there are different methods to
control the single instance of a program. I've tried the following
method
class CSingleton
{
public:
CSingleton& GetInstance(){ static CSingleton s; return s; }
How can you call this method and how would you change its definition if
you did want to call it?
private:
CSingleton(){}
~CSingleton(){}
}
It wouldn't compile with any compiler without the missing semicolon.
The above code failed to compile in Visual C++ 6.0
Never trust that compiler, it's old and not very standards compliant.
--
Ian Collins.
Dear All,
I'm extremely sorry to paste wrong code. Please refer this one.
class CSingle
{
public:
static CSingle& GetInstance(){ static CSingle s; return s; }
private:
CSingle() { cout<<"ctor"; }
~CSingle() { cout<<"dtor"; }
};
Sorry for the incovenience.Please refer this code for my question
Regards,
Sarath
declare your destructor public. No reason to hide it.
So what about the compiler generated copy constructor?
int main()
{
CSingle instance;
CSingle copy(instance);
}
and assignment? etc...
It will work if I make the dtor public. But I just want to know about
the destruction of static objects in the above scenario. As All
compilers behaves in different manner.
Regards,
Sarath
.