Can functions accept abstract base classes as arguments?

后端 未结 2 679
天命终不由人
天命终不由人 2020-12-30 02:10

Having gotten comfortable with the idea of basic classes and encapsulation, I\'ve launched myself towards understanding polymorphism, but I can\'t quite figure out how to ma

2条回答
  •  萌比男神i
    2020-12-30 02:54

    You will need to pass a reference instead of a copy:

    void speakTo(Animal& animal) {
        animal.speak();
    }
    

提交回复
热议问题