pointer_cast_dy_fail3.cpp 505 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // A negative test for unique_ptr dynamic_cast
  3. //
  4. // Copyright 2016 Peter Dimov
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. //
  10. #include <boost/pointer_cast.hpp>
  11. #include <memory>
  12. struct B
  13. {
  14. virtual ~B()
  15. {
  16. }
  17. };
  18. struct D: B
  19. {
  20. };
  21. int main()
  22. {
  23. std::unique_ptr<D[]> p1( new D[ 1 ] );
  24. std::unique_ptr<B[]> p2 = boost::dynamic_pointer_cast<B[]>( std::move( p1 ) );
  25. }