Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Chapter 10. The Conversion Library 1.6

Bjarne Stroustrup

Dave Abrahams

Boris Rasin

Antony Polukhin

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Table of Contents

Description
Polymorphic casts
polymorphic_cast, polymorphic_downcast, polymorphic_pointer_cast and polymorphic_pointer_downcast synopsis
polymorphic_downcast example
polymorphic_pointer_downcast example
History

The Conversion Library improves program safety and clarity by performing otherwise messy conversions. It includes cast-style function templates designed to complement the C++ Standard's built-in casts.

To reduce coupling, particularly to standard library IOStreams, the Boost Conversion Library is supplied by several headers:

  1. The boost/polymorphic_cast.hpp header provides polymorphic_cast<> and polymorphic_downcast<> to perform safe casting between polymorphic types.
  2. The boost/polymorphic_pointer_cast.hpp header provides polymorphic_pointer_cast<> and polymorphic_pointer_downcast<>
  3. The boost/implicit_cast.hpp header provides implicit_cast<> to perform implicit casts only (no down-cast, no void*->T*, no U->T if T has only explicit constructors for U).
  4. The boost/lexical_cast.hpp header provides lexical_cast<> general literal text conversions, such as an int represented as a string, or vice-versa.

PrevUpHomeNext