I know dynamic casts works on pointers and references. Both of the following work casting downwards
der d;
base& b = d;
der x = dynamic_cast<der&>(b); -->A
der& y = dynamic_cast<der&>(b); -->B
x.method();
y.method();
I wanted to know what the difference is between A and B
The line
constructs an object of type
der
and initializes it withdynamic_cast<der&>(b)
The line
just initializes a reference.
calls
method()
on the separately constructed object.calls
method()
on the objecty
references, which isd
.