Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is different between static member function and global function?

Tags:

c++

What is different between static member function and global function?

void globalFunc()
{
}

class Test
{
  public:
    //In grammar side, object's not own this function
    static void staticFunc(); 
};

The static member function is global function but, it can classify with meaning and limit access range.

But i can not understand why the static member function's calling convention is a [this call].

I understand that normal member function must be [this call] because it must need the caller object's address but, why the static member function has a this call convention? I think it does not need caller's address, because it is not object's function. Is there have any difference between static member function and global function? (Not in grammar side But also low side)

like image 661
HelloWorld Avatar asked Jan 03 '23 11:01

HelloWorld


1 Answers

Static class functions can

  • access private and protected static data members within a class.
  • access private and protected static functions.
  • access private and protected per-instance data members within a class if the static function has an instance of the class.
  • access private and protected per-instance functions if the static function has an instance of the class.
  • shadow functions of the same name in base classes.
  • access protected data and functions in base classes.

Global non-friend functions can do none of those.

like image 55
LincolnMan Avatar answered Feb 06 '23 13:02

LincolnMan