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

Friend Class In C++ | Friend Class In C++ With Example | Friend Class In C++ Syntax | Friend Class In C++ Hindi

Friend Class In C++


Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful to allow a particular class to access private members of other class.

 

image of Friend Class In C++

Fig: Friend Class In C++

Syntax:

class B;

class A

{

private:

data member;

public:

friend class B;

};

 

Program:

#include<iostream.h>

#include<conio.h>

class A

{

private:

int a;

public:

A()

{

a=10;

}

friend class B;

};

class B

{

private:

int b;

public:

void show(A & x)

{

cout<<”x.a=”<<x.a;

}

};

void main()

{

A  a;

B  b;

b.show(a);

getch();

}

         

Output:

x.a 10


No comments:

Post a Comment