Topic: dynamic_cast< T* > ( T*& ) legal?


Author: Marcus Barnes <marcus_aurelius@my-dejanews.com>
Date: 1999/04/28
Raw View
Hi All,

A codeveloper of mine has written a function template to abbreviate the new
style cast syntax, for example:

template< class To, class From >
inline
To dcast ( From& from )
{
    return dynamic_cast< To > ( from );
}

... and uses this for both pointer and reference conversions. Now I wonder if
passing a reference to a pointer, and getting a pointer back, is well defined
and legal:

{
    class foo {};
    foo* duh;
    void* blah = dcast< void* > ( duh ); // duh is passed as foo*&
}

... since the draft describes pointer semantics separately from reference
semantics wrt dynamic_cast:

""
2 If  T is a pointer type, v shall be an rvalue of a pointer to complete
  class type, and the result is an rvalue of type T.  If T is  a  refer-
  ence  type,  v  shall  be  an lvalue of a complete class type, and the
  result is an lvalue of the type referred to by T.
""

Can I get a clarification on this?

--
Regards, Marcus

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]