Online Classes

Results can only be achieved if you have the focused direction and crystal clear knowledge. To achieve this, you need a mentor. We will help you out by connecting with an expert mentor in the field.

Learn More

Article

Static Functions in C++ Programming - Codzify.com

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 <iostream>
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 <iostream>
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<

Try to execute what you have learnt

Easy to use online data structure compiler where you can execute the programs in your favourite programming language.
(C, C++, Python)

Open Compiler

HTML, CSS and Javascript Real time Web Editor

Execute your HTML, CSS and javascript code in real time with the web editor
(HTML, CSS, Bootstrap, Javascript)

Open Web Editor