Virtual friend functions for a base class?

前端 未结 5 682
情书的邮戳
情书的邮戳 2020-12-14 21:56

I\'m in the proccess of learning the language and this is a noob doubt.

Is it possible to use a virtual friend function? I don\'t know if it\'s possible, I didn\'t

5条回答
  •  暖寄归人
    2020-12-14 22:06

    Virtual Functions are something else than friend functions. Virtual Functions are used only with use of inheritance in the program with one class as base class and other as derived classes. Virtual functions are used for dynamic binding of objects. It means that you can store an object of derived class in a pointer of base class and still call the method of that partiular derived class. The concept is known as Polymorphism.

    Friend functions are used to access the private interface of a class. They could be used even when no inheritance has been used in your class.

提交回复
热议问题