"Krice" <pa****@mbnet.fi> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Is it possible that construction of a global instance can fail?
I'm suspecting this because the program seems to crash before
main(). Is it a better practice to declare a pointer for the
object and then use 'new' to create an instance?
It's better practice to write code that doesn't crash. :-)
(Sorry, couldn't resist.)
Construction of an object certainly can fail. Likely reasons are undefined
bahavior exhibited by your constructor, or making assumptions about the
_order_ in which such global objects are constructed.
You should probably debug the software, setting breakpoints in any
constructors or other code that might get called during startup.
But simply switching to dynamic allocation isn't neccessarily going to help
at all. It might, but then again it might not. Or, it might appear to
work, but only mask the real problem. Better to find out exactly why it's
crashing.
Some might suggest never using a global instance of anything. I'd suggest
_avoiding_ global instances, but there are cases where it's perfectly
appropriate.
-Howard