C ++: Difference between non-member function and static member function?

A simple question: what is the difference between a static member function, i.e. a function that can be called without requiring access to it (just using the class identifier) ​​and a non-member function? Here I ask conceptually and functionally.

Are non-member elements conceptually static?

+4
source share
3 answers

static member functions can access private and protected sections of a class. Functions that are not members cannot do this by default. They can only do this if the class provides them with friendship.

, , - , - . - , .

+6

@R Sahu, .:)

. , , .

+1

Another advantage of a static member function is that this is the only way if you want to call it in a thread in the Windows API. CreateThread requires the function to be in global space, or, if it is a member function, it must be static. And at least I know about this.

0
source

Source: https://habr.com/ru/post/1537581/


All Articles