Compiler Warning (level 1) C4540

dynamic_cast used to convert to inaccessible or ambiguous base; run-time test will fail ('type1' to 'type2')

You used dynamic_cast to convert from one type to another, but the compiler was able to determine that the cast would always fall (return NULL) because a base class is inaccessible (the base class is private, for instance) or ambiguous (the base class appears more than once in the class hierarchy, for instance).

The following shows an example of this warning. Class D is derived from class B. The program uses dynamic_cast to cast from class D (the derived class) to class B, which will always fail because class B is private and thus inacessible. Changing the access on B to public will fix the problem.

class B { virtual void g(); };
class D : private B {};

void a() {
   D   d;
   B*   bp;
   bp = dynamic_cast<B*>(&d); // error C4540
}