reverse_iterator and const_reverse_iterator

J

James Kanze

Thanks. So if I cast an object to a pointer type or other class type,
but not ref-type, then new an object is always created; in the case of
the pointer,the new object is a pointer that has the same value as the
old pointer hence they point to the same object and we can modify the
object through the new pointer. If I cast the object to a ref-type,
then there is no object created at all, not even the pointer, is this
right?

Almost. The case of casting to a reference type is a bit more
subtle; basically, "static_cast<T&>(v)" works exactly like: "T&
ref( v )", but without the name "ref". If the value being
converted is an lvalue, and reference compatible (i.e. the type
can somehow be directly bound to the reference), then there is
no new object. Otherwise, the reference must be to const, and
you may very well get a new object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,292
Messages
2,571,494
Members
48,180
Latest member
DelmarCarv

Latest Threads

Top