Abstract class and unique pointer

前端 未结 4 962
北海茫月
北海茫月 2021-02-13 21:05

I have the following error in my code:

error: allocating an object of abstract class type \'Material\'

I don\'t know how to handle this case.

4条回答
  •  一向
    一向 (楼主)
    2021-02-13 21:41

    http://www.cplusplus.com/forum/beginner/236974/ contains the proper solution. The make_shared should be of the specific type; you can then without issues store this in a unique_ptr of the abstract type.

提交回复
热议问题