Esoteric C++ operators

前端 未结 6 505
渐次进展
渐次进展 2020-12-28 08:37

What is the purpose of the following esoteric C++ operators?

Pointer to member

::*

Bind pointer to member by pointer



        
6条回答
  •  没有蜡笔的小新
    2020-12-28 09:25

    These allow you to have pointers to member functions (and member variables) that are tied to a particular instance of the class.

    Pointers to member functions can be useful for things like lightweight implementations of the state pattern. Generally, any time you want to vary the behavior of an object over time without resorting to switching out the entire object, you can consider the use of pointers to member functions.

    Pointers to member variables can be used if you want to, e.g., implement a generic algorithm to search an array of structs for an entry that has a particular value for a given field.

提交回复
热议问题