Difference between Static and Friend Function in C++ Last Updated : 28 Dec, 2022 Comments Improve Suggest changes Like Article Like Report Static Function: It is basically a member function that can be called even when the object of the class is not initialized. These functions are associated with any object and are used to maintain a single copy of the class member function across different objects of the class. This function is denoted by using the static keyword. Friend Function: It is basically a function that is especially required for accessing non-public members of the class. It has the right to access all private and protected members of the class. It usually provides some additional functionality that is not normally used by class and allows sharing class information by non-member function. Tabular difference between Static Function and Friend Function: Static Function Friend Function It is a member function of a class that is called even when the object of the class is not initialized.It is a function that is declared outside the class scope.In this, it cannot access any variable of its class except for static variables.In this, it can access private and public members of the class.It is denoted by placing a static keyword before the function name.It is denoted by placing a friend keyword before the function name.This function is generally used to make function members independent of any particular object of the class.This function is generally used to access non-public members of the class.These functions are normally used when one wants a function that is the same for every instance of the class. These functions are normally used to share information of class that was hidden previously.It can have access to members of one class. It can have access to members of several classes. It cannot be used when one needs to overload operators. It can be used when one needs to overload operations because overloading operators can only be done through friends or non-static members. It can also be used if the function has no need to read, change or modify the state of a particular instance of the class or if one needs to use function pointer to a member function of class. It can also be used when one wants to create code that not a member of the class and should not be a member of their class. This function can be hidden behind privileges. This function cannot be hidden and anyone may call the friend function. It is associated with class and not an object. It is declared in class but does not belong to the class. Comment More infoAdvertise with us Next Article Difference between Static and Friend Function in C++ M madhurihammad Follow Improve Article Tags : Difference Between C++ Functions C++-Static Keyword C++-Friend function and class +1 More Practice Tags : CPPFunctions Similar Reads Difference Between Friend Function and Virtual Function in C++ A friend class can access private and protected members of other classes in which it is declared as friend. It is sometimes useful to allow a particular class to access private members of other classes. Just likely, a friend function is a function that is declared outside the scope of a class. This 3 min read Difference between virtual function and inline function in C++ Virtual function: Virtual function is a member function which is declared within a base class and is redefined by a derived class. Inline function: Inline function is a normal function which is defined by the keyword inline, it is a short function which is expanded by the compiler and its arguments 2 min read Difference Between Inline and Normal Function in C++ Inline Function is a function that is expanded inline by the compiler when it is invoked. During function call, a lot of overhead tasks are performed like saving registers, pushing arguments to the stack, and returning to the calling function. These overheads are time-consuming and inefficient for s 4 min read Difference between Virtual function and Pure virtual function in C++ Virtual Function in C++ A virtual function is a member function which is declared within a base class and is re-defined(Overridden) by a derived class. When you refer to a derived class object using a pointer or a reference to the base class, you can call a virtual function for that object and execu 2 min read Difference between Static and Shared libraries In programming, a library is a collection of pre-compiled pieces of code that can be reused in a program. Libraries simplify life for programmers, in that they provide reusable functions, routines, classes, data structures and so on which they can be reused in the programs. Static Libraries: A Stati 2 min read Like