Algorithmic Pitfalls
The first group of pitfalls you find here are those hidden in algorithmic choices. These are the kinds of pitfalls you have run into or read about just to find out they exist.
Arrays and Inheritance
Arrays of objects—structures, classes, and base types—are a popular storage structure (refer to Chapter 11, "Storage Structures" ). However, when using arrays in combination with inheritance there is something to watch out for, as shown in Listing 15.1.
Code Listing 15.1. Incorrect Use of Object Arrays
#include <iostream.h> class AverageJoe { public: long socialSecurityNumber; } ; class JetSet : public AverageJoe { public: long VIP; } ; void SetSocialSecurity(AverageJoe* person, long id, long number) { person[id].socialSecurityNumber ... |
Get C++ Footprint and Performance Optimization now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.