Archive for the ‘Programming Languages’ Category

At some point, you find yourself writing a C++ method that ends up having a lot of repetitious code that is very context-specific to that method. Sure, you could create a private method that encapulates the repetitious code. But, that approach brings about 2 problems that I respectively call class namespace pollution (declarations at class [...]

Writing long constructors that perform a number of operations outside of merely initializing data members is generally discouraged due to the inherant problems with error handling. However, there are times when an object must undergo complex initialization before it can be used. Generally, I prefer to make such initialization as transparent as possible to simplify [...]

There are cases where you must provide a pointer to an instance of a C++ class but you need to prevent the object from being destroyed via operator delete. The preferred approach is to make the class destructor either protected or private. Doing this will cause the compiler to generate an error when calling delete [...]

To quickly initialize a data structure with all zeros (i.e. zero’ed memory), do this: SOME_STRUCT myStruct = { NULL };