Re: dynamic_cast
On 21 Nov., 21:45, "Daniel Kr?gler" <daniel.krueg...@googlemail.com>
wrote:
On 21 Nov., 12:36, Francis Glassborow
Given
struct A {}
struct B {}
bool foo(A* a_ptr){
B* b_ptr(dynamic_cast<B*> a_ptr);
....
}
The compiler cannot know that somewhere a programmer will write:
struct C: A, B {}
This is not the use-case of the OP and is not the point I was
discussing, because in the OP's use-case the source type is
a *derived* type and the destination type is the *base* type.
According to my understanding of p. 5 the initial check for this
decision block bases on the static type information. In your
example above this use-case does not apply, so the following
p. 6 (run-time check) will be performed - according to the
opinion of both you and me, right?
And to complete this deduction: Because p. 6 requires
a polymorphic type - which is not given here - this
program should also be ill-formed.
Now sonsider the code:
void bar(C c_ptr){
bool test( foo(c_ptr) );
....
}
The call to foo() is well formed and the dynamic_cast will succeed.
Absolutely correct, but I don't think that this addresses the OP's
use-case, am I wrong?
Not correct, because I overlooked my own argumentation-
chain here (the fact that the type is not polymorphic) -
I apologize for the entropy increase ;-)
Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]