Skip to main content
added 103 characters in body
Source Link
synepis
  • 1.3k
  • 17
  • 29

Static functions are used when you want a function that is the same for every instance of a class. Such functions do not have access to "this" pointer and thus cannot access any non static fields. They are used often when you want a function that can be used without instantiating the class.

Friend functions are functions which are not in the class and you want to give them access to private members of your class.

And this(static vs. friend) is not a matter of using one vs the other since they are not opposites.

Static functions are used when you want a function that is the same for every instance of a class. Such functions do not have access to "this" pointer and thus cannot access any non static fields. They are used often when you want a function that can be used without instantiating the class.

Friend functions are functions which are not in the class and you want to give them access to private members of your class.

Static functions are used when you want a function that is the same for every instance of a class. Such functions do not have access to "this" pointer and thus cannot access any non static fields. They are used often when you want a function that can be used without instantiating the class.

Friend functions are functions which are not in the class and you want to give them access to private members of your class.

And this(static vs. friend) is not a matter of using one vs the other since they are not opposites.

Source Link
synepis
  • 1.3k
  • 17
  • 29

Static functions are used when you want a function that is the same for every instance of a class. Such functions do not have access to "this" pointer and thus cannot access any non static fields. They are used often when you want a function that can be used without instantiating the class.

Friend functions are functions which are not in the class and you want to give them access to private members of your class.