Can someone tell me why this is not compiling:
struct A { };
struct B : public A { };
int main()
{
B b;
A* a = &b;
B* &b1 = static_cast<B*&>(a);
return 0;
}
Now, if you replace the static listing with:
B* b1 = static_cast<B*>(a);
then it compiles.
Edit: Obviously, the compiler treats A*and B*as independent types, otherwise it would work. The question is why is this desirable?
source
share