Monthly Archives: September 2011

Virtual Methods

Virtual functions are a fairly well-understood programming construct in terms of how and when to use them. But have you ever stopped to think about how they actually work under the hood? You’ve probably heard the term “vtable” thrown around … Continue reading

Posted in C/C++ | Tagged , | 7 Comments

Static asserts

One of the new features of C++11 is the ability to do a compile-time assertions. These assert functions are similar in concept to the runtime assert functions we all know and love. You pass in a constant expression and a … Continue reading

Posted in C/C++ | Tagged , | 1 Comment

Threading on Windows

Threads are becoming one of the more ubiquitous concepts in programming. Chances are quite good that you’ve a few of them before. But have you ever stopped to think about how a thread works under the hood? There are some … Continue reading

Posted in Win32 | Tagged , , | Leave a comment

Understanding Undefined Behavior

One of the harder concepts for people to understand in C++, in my opinion, is “behavior.” In C++, the language has some very specific wording for what the various behaviors are, and I’ve seen a lot of people get them … Continue reading

Posted in C/C++ | Tagged , | Leave a comment

Be Carefully Consistent With Memory

One of the things that most C/C++ programmers start to take for granted is memory. It’s always there, and when used properly, it always “just works.” However, frameworks throw a bit of a monkey wrench into the equation because they … Continue reading

Posted in Framework Design | Tagged , , | 1 Comment

Preventing Evil Operator Overloading

While doing some research on allocators, I noticed that the language specification has some interesting wording with regards to getting the address of an element from an allocator. Specifically, it says (Section 20.6.9.1 Clauses 2 & 3): Returns: The actual … Continue reading

Posted in C/C++ | Tagged | Leave a comment

Contextual Keywords

I believe the C++ standards committee got some things wrong in the distant past. Converting constructors work implicitly with an assignment operation, function hiding and overriding are not explicit, there’s no way to prevent a subclass from providing further overrides … Continue reading

Posted in C/C++ | Tagged , , | 2 Comments

Understanding Attributes

The new C++11 standard includes the ability to specify “attributes” for various declarations. The concept of attributes will be familiar to you if you’ve done work in languages like C# or Java. However, there are major differences between C++ attributes … Continue reading

Posted in C/C++ | Tagged , , | Leave a comment

When to be Explicit

In C++, a constructor that accepts a single parameter non-defaulted parameter is also considered a converting constructor. Converting constructors allow you to initialize a class instance using that single parameter type either via explicit construction, or via an assignment construction. … Continue reading

Posted in C/C++ | Tagged , | 2 Comments

What I Learned Today About Virtual Functions

What is wrong with the following class declarations? It turns out that the correct definition is the one to Bar, which came as a surprise to me.

Posted in C/C++ | Tagged | 2 Comments