Confusion about static initialization for static members of templates
template <typename type> class SSmallMemory
{
protected:
static SFixedAllocator classAllocator;
};
template <typename type> SFixedAllocator SSmallMemory<type>::classAllocator =
SFixedAllocator(sizeof(type), 1024);
I guess this is the thing I really dislike about C++, the core problem that keeps it from being easy to program in. It always seems to be my bane trying to keep things initialized properly without incurring too much overhead or going into awkward programming ‘idioms’ that are a pain to maintain.
I cut out the irrelevant part of the template so as not to get too off track.
Basically, what happens here? Is this safe to use in this manner or am I playing with fire? Though I’ve read a lot on this stuff and revisited it time and again I am not sure what happens here. Since anything using the template is going to include the header it’s in, then will the allocator always be initialized before the class gets used, or am I living in a fantasy land to think so?
See more here:
Confusion about static initialization for static members of templates
31