The word cast is the name of a syntax construct. These are all casts:
(any_typename) foo
static_cast<any_typename>(foo)
reinterpret_cast<any_typename>(foo)
A cast may also be called an explicit conversion. Conversions that are not written with cast notation are called implicit.
Conversions may or may not be implementable as a "raw bits copy". The conversion int i = f;
(with or without the cast operator - makes no difference) can't be. However, long x = 5; int i = x;
could be, if int
and long
are the same size on that platform.
Another conversion that could be a raw bit copy is char *ptr = "hello"; void *q = ptr;
. In general, other pointer conversions might not be raw bit copies.
Conversions between user-defined types (i.e. class types) can only occur if the class has a conversion operator or converting constructor defined, and in this case you write code that specifies how the conversion is performed.