On Dec 21, 9:41 am, Salt_Peter <pj_h...@yahoo.comwrote:
Quote:
On Dec 21, 3:11 am, Sarath <CSar...@gmail.comwrote:
Quote:
Quote:
I'm extremely sorry to paste wrong code. Please refer this one.
Quote:
Quote:
class CSingle
{
public:
static CSingle& GetInstance(){ static CSingle s; return s; }
Quote:
Quote:
private:
CSingle() { cout<<"ctor"; }
~CSingle() { cout<<"dtor"; }
};
Quote:
Quote:
Sorry for the incovenience.Please refer this code for my question
Quote:
declare your destructor public. No reason to hide it.
There's also no reason to make it public, since the code should
work if the destructor is private as well. (A long time ago,
this was a frequent error, since the pre-standard specification
wasn't too clear as to where access of the destructor should be
checked. But any modern compiler should get it right.)
Quote:
So what about the compiler generated copy constructor?
Good point.
Quote:
int main()
{
CSingle instance;
CSingle copy(instance);
}
Quote:
and assignment? etc...
Assignment would require two instances, or... Making it private
certainly doesn't hurt, however, and IMHO makes the intent
clearer.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34