Topic: dynamic_cast<const B&>
Author: "Nathan Myers, http://www.cantrip.org/" <ncm@cantrip.org>
Date: 1996/03/24 Raw View
Martin E. Nordberg III wrote:
>
> I just installed MS VC++ 4.1. The following code (strained
> from my larger code) now fails to compile:
>
> class A { virtual ~A() };
> class B : public A {};
>
> void test( const A& a )
> { const B& b = dynamic_cast<const B&>( a ); }
>
> Did Microsoft goof ... ?
"Heh heh heh."
But seriously... new implementations from the Draft are bound to
have mistakes. What's important is whether they get fixed after
attention is called to them. I'll be interested to see whether
the next release still has this bug.
Nathan Myers
ncm@cantrip.org http://www.cantrip.org/
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "Martin E. Nordberg III" <102571.1562@CompuServe.COM>
Date: 1996/03/22 Raw View
I just installed MS VC++ 4.1. The following code (strained
from my larger code) now fails to compile:
class A { virtual ~A() };
class B : public A {};
void test( const A& a )
{
const B& b = dynamic_cast<const B&>( a );
// gives "... error ... cannot use dynamic_cast to
// convert from 'const A &' to 'const B &' "
}
Did Microsoft goof or did I? The draft standard (Sect. 5.2.6)
seems to equate a reference to an lvalue for dynamic_cast, but
gives no clear wording for this case. The same problem happens
for const A* to const B*.
If the new MSVC++ behavior is correct, why?
(Eagerly awaiting BC++ 5.0, hope it really works with MFC)
--
Martin E. Nordberg III
Quintessoft Engineering, Inc.
"Visualizing new patterns of software development."
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]