What is the use of private static member functions?

前端 未结 5 2127
一生所求
一生所求 2021-01-31 07:37

I was looking at the request parser from the boost::asio example and I was wondering why the private member functions like is_char() are static? :

5条回答
  •  渐次进展
    2021-01-31 08:33

    It's static, since it doesn't require access to any member variables of request_parser objects. Hence, making it static decouples the function since it reduces the amount of state which the function can access.

    For what it's worth, it would have been even better if this function wasn't part of the request_parser class at all - instead, it should have been (possibly in a namespace) a free function in the .cpp file.

提交回复
热议问题