Confusion about static initialization for static members of templates

Written by

Code:


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

Oct
31

Do While Loops

Written by

Hi everyone,

Before i start i’ve gotta admit i’m new when it comes to coding. For our college work we’ve gotta create a programme that lets a user input some numbers until 0 is entered. Upon entering 0 the programme then spits out how many of the numbers put in are even and how many are odd. Now we’ve been told we’ve gotta use the modulus division and a do while loop, but i’ve got completely stuck and have no idea what to do.

Cheers for any help,
Regards,
Weems316.

The rest is here:
Do While Loops

Oct
31