Google
 
Webcprogramming.com




An Affiliate of AIHorizon




Static-cast Typecast

Static casts are only available in C++. Static casts can be used to convert one type into another, but should not be used for to cast away const-ness or to cast between non-pointer and pointer types. Static casts are prefered over C-style casts when they are available because they are both more restrictive (and hence safer) and more noticeable.

Static casts are expressed in terms of a template that takes as a template parameter the type to convert to.
static_cast<<type>>(<value>);
This example casts an int to a double for the purpose of avoiding truncation due to integer division:
double result = static_cast<double>(4)/5;


-----
Interested in advertising with us?
Please read our privacy policy.
Copyright © 1997-2005 Cprogramming.com. All rights reserved.

Geodesy Designs