Difference between Reference and Pointer

The key difference between pointers and references is that there is no such thing like null reference. A reference is always identifies a valid object in the memory.


    Base *bp = ...;

    // null, if dynamic_cast is invalid
    if ( Derived *dp = dynamic_cast<Derived*>(bp) )
    {
        // ...
    }


    Base &br = ...;

    // throws exception, if dynamic_cast is invalid
    try
    {
        Derived &dr = dynamic_cast<Derived&>(br);
        // ....
    }
    catch( bad_cast ) { ... }