fork download
  1. #include <memory>
  2.  
  3. struct X
  4. {
  5. };
  6.  
  7. struct Y : X
  8. {
  9. };
  10.  
  11. int main()
  12. {
  13. std::shared_ptr<X> pX = std::make_shared<Y>();
  14. std::shared_ptr<Y> pY = std::dynamic_pointer_cast<Y>(pX);
  15. }
  16.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/4.7/memory:87:0,
                 from prog.cpp:1:
/usr/include/c++/4.7/bits/shared_ptr.h: In instantiation of ‘std::shared_ptr<_Tp1> std::dynamic_pointer_cast(const std::shared_ptr<_Tp2>&) [with _Tp = Y; _Tp1 = X]’:
prog.cpp:14:64:   required from here
/usr/include/c++/4.7/bits/shared_ptr.h:450:50: error: cannot dynamic_cast ‘(& __r)->std::shared_ptr<X>::<anonymous>.std::__shared_ptr<_Tp, _Lp>::get<X, (__gnu_cxx::_Lock_policy)2u>()’ (of type ‘struct X*’) to type ‘struct Y*’ (source type is not polymorphic)
stdout
Standard output is empty