Static member functions

后端 未结 5 1300
自闭症患者
自闭症患者 2020-12-08 16:30

After reading sbi and Eli Bendersky\'s answers in this question I started to wondering what static member functions are for.

A class\' friend free function shouldn\'

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 17:02

    Often, frankly, you shouldn't. Free functions are vastly under-rated.

    The implicit "namespacing" you get from using a static member (pretending that the class is nothing more than a namespace for the static member, which is sort of true) is the only benefit that I can think of.

    If the static function member needs persistent variables, the ability to have static data members along with it might also be useful.

提交回复
热议问题