What is the practical use of pointers to member functions?

后端 未结 12 1524
醉酒成梦
醉酒成梦 2020-12-03 08:13

I\'ve read through this article, and what I take from it is that when you want to call a pointer to a member function, you need an instance (either a pointer to one or a sta

12条回答
  •  长情又很酷
    2020-12-03 08:45

    My question is based on this: since you have the instance, why not call the member function directly[?]

    Upfront: In more than 15 years of C++ programming, I have used members pointers maybe twice or thrice. With virtual functions being around, there's not all that much use for it.

    You would use them if you want to call a certain member functions on an object (or many objects) and you have to decide which member function to call before you can find out for which object(s) to call it on. Here is an example of someone wanting to do this.

提交回复
热议问题