Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Static constructors and destructors?

20 views
Skip to first unread message

Rick C. Hodgin

unread,
Mar 13, 2017, 12:05:01 PM3/13/17
to
Does C++ offer a static constructor? Something that can be called at
startup to initialize anything specific to static members of a class?

Something like:

class xyz
{
public:
xyz(); // Called for each instance
~xyz(); // Called for each instance

static xyz(); // Called at startup
static ~xyz(); // Called at normal shutdown
}

Or do I need to define my own separate un-encapsulated function
somewhere which then initializes any values I might need for the
class before it's used the first time, so as to not take the test-
on-each-instantiation/deinstantiation performance hit?

Thank you,
Rick C. Hodgin

Bonita Montero

unread,
Mar 13, 2017, 12:32:01 PM3/13/17
to
I think the best way would be to define another class (maybe
a nested class) and have a static member in the class needing
something like a "static constructor".

--
http://facebook.com/bonita.montero/
0 new messages