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

后端 未结 3 2038
后悔当初
后悔当初 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

    'dynamic_cast' : 'my_namespace::A' is not a polymorphic type because it doesn't define or inherit a single virtual function. Just add a virtual destructor and you'll be fine.

    dynamic_cast works only for such 'polymorphic' types.

提交回复
热议问题