Next: High Integrity CPP Guideline 17.6  Up: 17 Standard Template Library (STL)  Previous: High Integrity CPP Guideline 17.4  Contents

High Integrity CPP Rule 17.5   Do not attempt to insert derived class objects in a container that holds base class objects.

Justification

If you attempt to insert an object of derived type into a container of base type objects then slicing will occur and the container will not hold the intended object. The problem of slicing is eliminated when pointers to base class objects are stored.

See also

Rule 11.4, Guideline 17.4

Reference

Effective STL Items 3, 7;


HICPP VERSION 2.4  http://www.codingstandard.com   Copyright: © 2007 THE PROGRAMMING RESEARCH GROUP