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

Launch Your Dating App with FlutterFlow: Course + Template
Master FlutterFlow and Build Your Dating App with Our Step-by-Step Course and Ready-Made Template.
Launch Your Grocery Delivery App with FlutterFlow: Course + Template
Master FlutterFlow and Build Your Grocery Delivery App with Our Step-by-Step Course and Ready-Made Template.
Launch Your Courses App with FlutterFlow: Course + Template
Master FlutterFlow and Build Your Courses App with Our Step-by-Step Course and Ready-Made Template.
Codzify Logo

Terms and Conditions    Cookie Policy   Refund Policy   Adsense Disclaimer

Contact: teamcodzify@gmail.com