C++ - How to access private members of a class, from a static function of the same class?

后端 未结 4 869
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 05:11

What I have:

So I have a class with a private member, and a static function. The function must really be static and I can\'t change that.

4条回答
  •  遇见更好的自我
    2021-01-17 05:19

    You can't. You need an instance to get to the non-static private. In the static method you don't have an instance available.

    So you need some way to get an instance, either by passing it to the static method, or by being able to get it from somewhere else. But in that case, you could as well make it a non-static method.

提交回复
热议问题