Re: curiosity singleton pattern?
On Aug 1, 11:21 am, Chris Forone <4...@gmx.at> wrote:
Ian Collins schrieb:>> //return sole ? sole : new (std::nothrow) Sc=
ene;
Why is this line commented out?
for testing operator new not successful
return sole; // for testing purposes only
}
int Print(void) // normaly only with valid objects?!
non static func Print is called by nullpointer?! have gcc
4.1 and linux os.
Why not? Don't forget that the object isn't used to call the member
function, which is just a plain old C function with an extra this
parameter, but is passed to the the function as the this parameter. In
your case, this isn't used.
sure?
That's doubtlessly the most frequent implementation---it's
obvious, easy to implement, and on modern processors, very
efficient. It's certainly not guaranteed, however, and I've
used compilers where the your code would result in a runtime
error of some sort, and it's not too hard to imagine cases where
such code would cause other data to be overwritten.
Don't count on what an implementation "typically" does. The
next release of the compiler might do something different.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34