title: Type cast error from shared_ptr
body: <p>I have the following code:</p>
  
  <pre><code>namespace {
      class CatBondEvent
      {
      public:
          CatBondEvent(Date date) : date(date){}
          virtual ~CatBondEvent(){}
          Date date;
  
          bool operator&lt; (CatBondEvent &amp;other) { return date&lt;other.date;}
      };
  
      class CatEvent : CatBondEvent
      {
      public:
          Real loss;
          CatEvent(Date date, Real loss) : CatBondEvent(date), loss(loss) {}
      };
  
      class CollateralCoupon : CatBondEvent
      {
      public:
          Real unitAmount;
          CollateralCoupon(Date date, Real unitAmount) : CatBondEvent(date), unitAmount(unitAmount) {}
      };
  
      class CatBondCoupon : CatBondEvent
      {
      public:
          CatBondCoupon(Date date) : CatBondEvent(date) {}
      };
  
      void fillEvents(std::vector&lt;boost::shared_ptr&lt;CatBondEvent&gt; &gt; &amp;events, 
                      Date startDate,
                      Date endDate,
                      boost::shared_ptr&lt;std::vector&lt;std::pair&lt;Date, Real&gt; &gt; &gt; catastrophes, 
                      boost::shared_ptr&lt;Bond&gt; collateral,
                      boost::shared_ptr&lt;std::vector&lt;Date&gt; &gt; couponDates)
      {
          for(int i=0; i&lt;catastrophes-&gt;size(); ++i) 
          {
              events.push_back(boost::shared_ptr&lt;CatBondEvent&gt;(new CatEvent((*catastrophes)[i].first, (*catastrophes)[i].second)));
          }
          const Leg&amp; cashflows = collateral-&gt;cashflows();
          for(int i=0; i&lt;cashflows.size() &amp;&amp; cashflows[i]-&gt;date()&lt;=endDate; ++i) 
          {
              boost::shared_ptr&lt;CashFlow&gt; cashflow = cashflows[i];
              if(cashflow-&gt;date() &gt;= startDate)
              {
                  events.push_back(boost::shared_ptr&lt;CatBondEvent&gt;(new CollateralCoupon(cashflow-&gt;date(), cashflow-&gt;amount())));
              }
          }
          for(int i=0; i&lt;couponDates-&gt;size(); ++i) 
          {
              Date couponDate = (*couponDates)[i];
              if(couponDate &gt;= startDate)
              {
                  events.push_back(boost::shared_ptr&lt;CatBondEvent&gt;(new CatBondCoupon(couponDate)));
              }
          }
      }
  }
  </code></pre>
  
  <p>And I get the following compilation errors:</p>
  
  <pre><code>Error   37  error C2243: 'type cast' : conversion from '`anonymous-namespace'::CollateralCoupon *' to '`anonymous-namespace'::CatBondEvent *' exists, but is inaccessible   c:\boost\boost_1_49_0\boost\smart_ptr\shared_ptr.hpp    184
  Error   36  error C2243: 'type cast' : conversion from '`anonymous-namespace'::CatEvent *' to '`anonymous-namespace'::CatBondEvent *' exists, but is inaccessible   c:\boost\boost_1_49_0\boost\smart_ptr\shared_ptr.hpp    184
  Error   38  error C2243: 'type cast' : conversion from '`anonymous-namespace'::CatBondCoupon *' to '`anonymous-namespace'::CatBondEvent *' exists, but is inaccessible  c:\boost\boost_1_49_0\boost\smart_ptr\shared_ptr.hpp    184
  </code></pre>
  
  <p>Any idea what went wrong and how to fix it?</p>