non-static vs. static function and variable

前端 未结 4 1524
無奈伤痛
無奈伤痛 2021-02-04 12:55

I have one question about static and non-static function and variable.

1) non-static function access static variable.

It\'s OK!

class Bar
{
publ         


        
4条回答
  •  梦谈多话
    2021-02-04 13:56

    For this, you need to understand what is static.

    Static data members exist once for the entire class, as opposed to non-static data members, which exist individually in each instance of a class. They will have a class scope and does not bound to an instance of the class.

    To access static member of the class, we use the format as below ::

    if you have created 10 objects of a class. Assume, you were able to access the non-static variable in the static member of the class, When the static function is called, which object's member it needs to change?

提交回复
热议问题