How do I pass a C++11 random number generator to a function?

后端 未结 4 2259
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 20:17

Do they all inherit from a base class? Do I have to use templates?

(I am referring to these http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c15319/)

4条回答
  •  温柔的废话
    2020-12-15 20:52

    I suggest two methods: Function Objects and Function Pointers. In either case, enable your class to receive a Function Object or a Function Pointer to the random number generator.

    With a Function Object, you can define a base class, and have your receiving class implement functions that require a pointer to the base function object class. This gives you more freedom in defining many different function objects without changing the interface of the receiving class.

提交回复
热议问题