Friend Functions in c++





This video tutorial explains the friend functions in c++.
You are gonna learn what is a friend function, how to declare a friend function, how to define a friend function, how to access the properties or members of a class in a friend function in detail with example.

source code for this tutorial

#include <iostream>
#include<string>

using namespace std;

class Human{
string name;
int age;

public:
    Human(string iname,int iage){
    name = iname;
    age = iage;
    }
    void tellme(){
    cout <<name<<endl<<age<<endl;
    }
 friend void display(Human man);

};

void display(Human man){
cout <<man.name<<endl<<man.age<<endl;

}


int main()
{
    Human anil("anil",24);
    display(anil);
    return 0;
}

 
Back To Top