C++: “… is not a polymorphic type” while using boost::dynamic_pointer_cast

后端 未结 3 2051
后悔当初
后悔当初 2021-01-01 14:28

Why do I receive the following error for the following code?

1>C:\\Libs\\boost_1_44\\boost/smart_ptr/shared_ptr.hpp(259): error C2683: \'dynamic_cast\' :          


        
3条回答
  •  难免孤独
    2021-01-01 15:07

    struct A has no virtual methods (not even a destructor), so you can't dynamic_cast from A* - only pointers to types with at least one virtual member function can be used dynamic_cast on. boost::dynamic_pointer_cast does dynamic_cast inside, to it's subject to same requirements.

提交回复
热议问题