polymorphic C++ references

前端 未结 7 1061
闹比i
闹比i 2020-12-09 09:07

I was wondering how you can do polymorphism with references, as opposed to pointers.

To clarify, see the following minimal example:

cl         


        
7条回答
  •  旧巷少年郎
    2020-12-09 09:45

    Still, is there a real need for dynamic memory allocation in this case?

    No. Just define A1 first and then make it a normal member of B.

    Polymorphism works just fine with both references and pointers.

提交回复
热议问题