Deleted Class Methods

One of the new features in C++0x is a declaration syntax allowing you to remove methods from a class entirely. While this may sound rather strange at first blush, it does have some interesting usages that will make your code cleaner and more readable.
Continue reading

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

Delegating Constructors

Delegating constructors are one of those minor language features that don’t get a lot of headlines, but make a programmer’s life much easier. It’s not likely something you’ll use on a daily basis, but it is something you will run across eventually.

Picking a real-world use case: let’s say you have a logging class which has three different constructors. Two constructors take a path as their parameter (one with a naked string pointer, another with a FilePath class), and the third constructor is the default constructor which places the logging file in a well-known location.
Continue reading

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

Typesafe Enumerations

C++0x has a lot of great new features included in it. However, the “flashier” features like lambda functions have the tendency to overshadow other features. One of those features which I am guessing will be overshadowed is the ability to create truly type safe enumerations in C++.
Continue reading

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

Enumerations for Framework Design

As someone who develops cross-platform and cross-language frameworks, a frequent problem I run up against are enumerations. They’re a very handy construct for a framework designer to use because they allow you to logically group related constants together with some degree of cohesion. However, they have some less-than-desirable behaviors.
Continue reading

Posted in Framework Design | Tagged | Leave a comment

Allocations Are Like a Game of Memory

Think of memory allocations and deallocations like a game of “memory”, where the only correct answer is to exactly match the cards. Failing to do so can lead to memory corruption that can sometimes be tricky to track down. The pairing should always be:
Continue reading

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

Automatic Type Inference

One of the nice new features introduced by C++0x is automatic type inference for declarations. Essentially, it means that the compiler will figure out the declaration type based on information from the right-hand side of the expression. If you come from C#, then this is something you’ve already seen with “var” declarations. In C++, you use the “auto” keyword for this.
Continue reading

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

Lambdas

What is likely to be considered the biggest, sexiest feature of the new C++0x specification goes by many names. Some folks call them “function objects”, others call them “closures”, and still others call them “lambda functions.” Regardless of what you call this feature, you’ll hopefully love it!
Continue reading

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

When Virtual Functions Aren’t Virtual

Let’s take a look at some innocuous-looking code and see if you can spot the bugs. If you can, you’re doing great!
Continue reading

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

Semantic Whitespace

No, this isn’t a blog posting about Python and its use of whitespace to denote statement blocks. This is actually a post about when whitespace matters in C++. It doesn’t happen particularly often, but whitespace can be important.
Continue reading

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

Generating a Minidump

Last time, I demonstrated a way to automatically generate a stack crawl to help you debug errors in your application. However, I also mentioned that stack crawls are usually not enough information by themselves. In this post, I am going to cover how to create a file with more complete debugging information. Not only will it contain stack crawls, but it will contain local and global variable information, thread and process information, and even application memory. All of this information will be collected into a single minidump file, which you can submit automatically.
Continue reading

Posted in Win32 | Tagged , | 22 Comments