Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

1. C++ Pocket Reference > Casts and Runtime Type Information

Casts and Runtime Type Information

Casts are used to explicitly convert an expression’s value to a different type. Runtime type information is type data embedded by the compiler for use at runtime.

C-Style Casts

C-style casting is the form of casting inherited from C. The target type is placed in parentheses immediately preceding the expression to be converted, as shown in the assignment to c below:

void              *v = new Circle(5.0);
Circle            *c = (Circle *)v;

With a C-style cast, no check is performed at runtime to ensure that the cast is reasonable. C-style casting can be used for the following:

  • Casting a pointer or arithmetic type to an integer type.

  • Casting any arithmetic type to a floating-point type.

  • Casting a pointer or arithmetic type to another pointer type.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint