C - C++ Pointers - Dynamic casting

#include <iostream>
using namespace std;
 
class base1 
{
public:
  virtual void cast(){cout << " In class base1\n";}
};
 
 
class base2 
{
public:
  virtual void cast() {cout << " In class base2\n";}
};
 
 
class derived: public base1, public base2 
{
public:
  void cast(){cout << "In derived class \n";}
};
 
 
int main()
{
  base1* b1 = new base1;
  base2* b2 = new base2;
  derived* d = new derived;
 
  b1-> cast(); b2 -> cast(); d -> cast();
  b2= dynamic_cast< base2*>(b1);  
  if (b2)  
    b2 -> cast();  
  else 
    cout << "no cast\n";
 
  b2 = dynamic_cast< base2*>(d);  //succeeds
  if (b2)
    b2 -> cast();  
  else 
    cout << "no cast\n";
 
  return 0;
}