Can a Static method access a private method of the same class?

前端 未结 5 1278
一个人的身影
一个人的身影 2020-12-10 01:15

I have this question because of the singleton/named constructor. In both cases, the real constructors are protected or private, neither of which can be accessed from outside

5条回答
  •  隐瞒了意图╮
    2020-12-10 01:58

    A static member function has the same access rights as a non static member function. So yes, it can access any public, protected, and private variable in the class. However you need to pass an instance of the class to the function for the function to be able to access the member. Otherwise a static function can only directly access any other static member in the class.

提交回复
热议问题