Static Functions in C++

Article by: Manish Methani

Last Updated: October 18, 2021 at 2:04pm IST
3 min 7 sec read

What are Member Functions ?

Member functions are the functions which are applied to the dataMembers of the class. Member functions can be declared inside a class or outside a class.

Member Functions defined inside a class

Example :-

#include 
using namespace std;
class Game
{
public:
  int i;       //data variable
  void  display(string str)

  { 
   cout<

Output :-

Save file as Game.cpp 
Open terminal
Access to the directory where Game.cpp is stored.

In terminal , then write this
g++ Game.cpp 
Once the file is compiled
 successfully, write this in terminal
./a.out

Snack Game
Pacman Game

Firstly main() function is called . Then it creates first instance of Game class named sankeObject. The display Method is called where it prints the passed the string using parameter str. Then it creates second object of Game class named pacmanObject. Then it calls a display function again with different string "Pacman Game."

Member Function defined outside the class

You can define the member functions outside the class using scope resolution operator written as two colons ::

Example :-

#include 
using namespace std;
class Game
{
public:
  int i;     // data member
  void  display(string str) ;  // Member Function Declaration

}; // Class ends here

//Member Function Defination
 void Game :: display(string str)  
  { 
   cout<

Discover My FlutterFlow Courses and Template Apps

FlutterFlow Course: Basic to Advanced (2025) – Dating App
Learn to Create the Dating App with Admin Dashboard using No-Code Tool FlutterFlow in this comprehensive course in 2025.
FlutterFlow Course: Learn to Build the Grocery Delivery App
Learn to Create Grocery-Delivery App in FlutterFlow, ideal for anyone looking to implement a functional E-Commerce App.
FlutterFlow Course: Learn to Build the Online Courses App
Learn to Create Online Courses App in FlutterFlow, ideal for anyone looking to implement a functional Courses App.
Codzify Logo

Terms and Conditions    Cookie Policy   Refund Policy   Adsense Disclaimer

Contact: teamcodzify@gmail.com