• When does static Object Initialization Occur?

    When working with static or global variables in C or C++, we know the compiler allocates storage for them in the application's data segment. However, when the variable is an instance of a C++ class, it must be initialized as well as allocated. While the C++ language specification explains when this initialization takes place, it is a rather simple matter to demonstrate the rules for clarity.

  • There's More Than One Way to Skin a Singleton

    After working with C++ for a while, we all come across situations where we need to create one and only one instance of a given object type. However, depending on your needs, there's more than one way to go about implementing a singleton.

  • const-antly Changing

    In addition to the virtual and inline method modifiers, C++ also allows the addition of the const modifier on class methods. The const modifier indicates the method does not alter the state of class member variables.

  • When virtual Functions Won't Fall inline

    C++ offers two useful modifiers for class methods: virtual and inline. A virtual method can inherit new behavior from derived classes, while the inline modifier requests that the compiler place the content of the method "inline" wherever the method is invoked rather than having a single instance of the code that is called from multiple places. You can think of it as simply having the compiler expand the content of your method wherever you invoke the method. But how does the compiler handle these modifiers when they are used together?

  • More Than Resource Contention

    One of the first things we learn about multithreaded programming is the need to guard against simultaneous read-write access to shared resources, but this isn't always a simple matter.