How to Declare a Static Member Function in a Class in C++? Last Updated : 27 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In C++, static functions are functions that are directly associated with a class so we can access the static function directly without creating an object of the class using the scope resolution operator. In this article, we will learn how we can declare a static function in a class in C++. Declare a Static Function in a Class in C++To declare a static member function, we can simply use the static keyword during the declaration of the function inside the class. Then we can use the scope resolution (::) operator to call the static function using the following syntax. Syntax to Declare a Static Member FunctionClassName:: static_Function().C++ Program to Declare a Static Function in a Class C++ // C++ program to declare a static function in a class #include <iostream> using namespace std; class Student { private: int marks; int id; string Name; public: // Declare a static function in the class static void staticFunc() { cout<<" Static function executed successfully"<<endl; } }; //Driver Code int main() { // Call the static function using scope resolution operator Student::staticFunc(); return 0; } Output Static function executed successfully Comment More infoAdvertise with us Next Article How to Declare a Static Member Function in a Class in C++? gaurav472 Follow Improve Article Tags : C++ Programs C++ cpp-class C++-Class and Object C++-Static Keyword CPP-OOPs CPP Examples +3 More Practice Tags : CPP Similar Reads How to Declare a Static Variable in a Class in C++? In C++, a static variable is initialized only once and exists independently of any class objects so they can be accessed without creating an instance of the class. In this article, we will learn how to declare a static variable in a class in C++. Static Variable in a Class in C++To declare a static 2 min read How to Create a Pointer to a Function in C++? In C++, a function pointer is a variable that stores the address of a function that can later be called through that function pointer. It is useful for passing functions as parameters to other functions(callback functions) or storing them in data structures. In this article, we will learn how to use 2 min read Calling a non-member function inside a class in C++ Member Function: It is a function that can be declared as members of a class. It is usually declared inside the class definition and works on data members of the same class. It can have access to private, public, and protected data members of the same class. This function is declared as shown below: 3 min read How to Check if a Template Class has the Given Member Function in C++? In C++ programming, we often need to check if a template class contains a specific member function. In this article, we will discuss how to check if a Template Class has the given member function or not. Check for the Member Function in a Template ClassWe can check whether a member function exists i 3 min read How to Sort using Member Function as Comparator in C++? In C++, sorting is a common operation that can be customized by providing a comparator function. When working with classes, we might need to sort objects based on their member variables. Using a member function as a comparator is a good technique to achieve this.In this article, we will learn how to 3 min read How to Create a Class with Private and Public Members in C++? In C++, the classes are blueprints for creating objects with specific properties and methods that provide a feature of access specifiers to the user through which they can control the access of the data members present in a class. In this article, we will learn how to create a class with private and 3 min read How to Call a Virtual Function From a Derived Class in C++? In C++, virtual functions play an important role because they allow the users to perform run-time polymorphism. While dealing with inheritance and virtual functions, it is very crucial to understand how to call a virtual function from a derived class. In this article, we will learn how to call a vir 2 min read How to Create a Static Library in C++? C++ allows users to add their own libraries to reduce the amount of code we have to write in our program. A static library in C++ is a library that is linked to the program at compile-time. In this article, we will learn how to create a static library in C++ from scratch. Create Static Library in C+ 3 min read How to Create a Template Class in C++? In C++, template classes are used to create generic classes that can work for different data types. In this article, we will learn how to create a template class in C++. Create a Template Class in C++ To create a template class in C++, we can follow the below syntax: Syntax of Template Classtemplate 2 min read Like