TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Thursday 4 June 2020

Static Member Function In C++ | Static Member Function In C++ With Example | Use Static Member Function In C++ | Static Member Function In C++ In Hindi

Static Member Function In C++


A static member function can be called even if no objects of the class exist and the static functions are accessed using only the class name and the scope resolution operator ::.

A static member function can only access static data member, other static member functions and any other functions from outside the class.

Static member functions have a class scope and they do not have access to the this pointer of the class. 

 

image of Static Member Function In C++

Fig: Static Member Function In C++


Syntax:


class  classname

{

data member;

public:

static return type functionname(argument list member function);

};



Program:

#include<iostream.h>

#include<conio.h>

class MCA

{

static int count;

int cd;

public:

void getdata();

void putdata();

static void output()

{

Cout<<”count=”<<count;

}

};

void MCA::getdata()

{

cout<<”example of static member function”;

cd=count++;

}

void MCA :: putdata()

{

cout<< cd;

}

int MCA::count

{

void main()

{

MCA a1;

a1.putdata();

a1.output();

a1.getdata();

a1.getdata();

a1.putdata();

a1.output();

getch();

}



Output:


Count=0

Example of static member function count=2

 

 


No comments:

Post a Comment