Compiler Error C2682

cannot use name to convert from 'type1' to 'type2'

An attempt was made to use a casting operator to convert between incompatible types. For example, you cannot cast use the dynamic_cast operator to convert a pointer to a reference.

Also note that the dynamic_cast operator cannot be used to cast away qualifiers. All qualifiers on the types must match. You can, however, use the const_cast operator to remove attributes such as const, volatile, or __unaligned.

The following is an example of this error:

class A { virtual void f(); };
class B: public A {};

void g(A* pa)
{
    B& rb = dynamic_cast<B&>(pa); // error
}