An lvalue of type “
cv1 B”, where
B is a class
type, can be cast to type “reference to
cv2 D”, where
D is a complete class derived (
[class.derived]) from
B,
if
cv2 is the
same cv-qualification as, or greater cv-qualification than,
cv1. If
B is a virtual base class of
D
or a base class of a virtual base class of
D,
or if no valid standard conversion from “pointer to
D”
to “pointer to
B” exists (
[conv.ptr]), the program is ill-formed
. An xvalue of type
“
cv1 B” can be cast to type “rvalue reference to
cv2 D” with the same constraints as for an lvalue of
type “
cv1 B”
. If the object
of type “
cv1 B” is actually a base class subobject of an object
of type
D, the result refers to the enclosing object of type
D. Otherwise, the behavior is undefined
. [
Example 1:
struct B { };
struct D : public B { };
D d;
B &br = d;
static_cast<D&>(br);
—
end example]