Program to demonstrate the friend function and friend class in c++

 #include<iostream>

using namespace std;

class Student

{

string Stu_name = "Vaibhav Yadav";

string branch = "Information Technology";

friend class MMMUT;

friend void studisplay(Student);

};

void studisplay(Student t){

    cout<<endl<<"Student branch is: "<<t.branch;

}

class MMMUT

{

public:

void display(Student t)

{

cout<<endl<<"Student Name is: "<<t.Stu_name;

}

};

main()

{

Student stu;

MMMUT clgstu;

clgstu.display(stu);

studisplay(stu);

return 0;

}


No comments:

Post a Comment

Operator Overloading in C++

#include<iostream> using namespace std; class Complex { private: int real, imag; public: Complex(int r = 0, int i = 0){       re...