My Favorite C++ Feature

What’s your favorite C++ feature? There are many to choose from. Encapsulation and polymorphism. Library features like iterators and algorithms. Templates and generic programming.
My favorite feature: destructors.
Destructors and C++ go together like peanut butter and jelly. I do my best work in destructors. So does much of the standard C++ library. Think about it for a moment. Our friend stl::vector would be a very poor container without a destructor. And tr1::shared_ptr would not be much use at all.
When I review code, I often find that the addition of a class or two with the right destructors can turn unreadable code into sublime code.
Here’s food for thought: the proper use of destructors and owned pointers (using shared_ptr or something similar) can eliminate resource leaks completely. A worthy goal indeed.
This entry was posted in C++. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s