Name

static_cast operator — Explicit cast operator

Synopsis

               postfix-expr := static_cast < type-id > ( expression )

The static_cast operator performs type conversions from one static type to another. It cannot cast away const or volatile qualifiers. A static cast can invoke built-in type promotions or conversions or user-defined type conversions with type conversion operators or constructors (including explicit constructors).

Example

char c;
if (isalpha(static_cast<unsigned char>(c))
  handle_alpha(c);

See Also

const_cast, dynamic_cast, explicit, expression, reinterpret_cast, Chapter 3

Get C++ In a Nutshell 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.