Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Object Oriented ProgrammingRSS Feeds

Program that provides an example of friend function of a class

Posted By: Julia Hughes     Category: C++ Programming     Views: 9611

Write a program that provides an example of friend function of a class.

Code for Program that provides an example of friend function of a class in C++ Programming

#include<iostream.h>
#include<conio.h>
class data2;
class data1
{
    int a,b;
    public:
        void get1();
        friend void sum(data1,data2);
};
class data2
{
    int c,d;
    public:
        void get2();
        friend void sum(data1,data2);
};

void sum(data1 a1,data2 a2)
{
    cout<<a1.a+a2.c<<endl;
    cout<<a1.b+a2.d<<endl;
}
main()
{
    data1 a;
    data2 b;
    a.get1();
    b.get2();
    sum(a,b);
}
void data1::get1()
{
    cout<<"Enter value for a: ";
    cin>>a;
    cout<<"Enter value for b: ";
    cin>>b;
}
void data2::get2()
{
    cout<<"Enter value for c: ";
    cin>>c;
    cout<<"Enter value for d: ";
    cin>>d;
}
  
Share: 



Julia Hughes
Julia Hughes author of Program that provides an example of friend function of a class is from London, United Kingdom.
 
View All Articles

 

Other Interesting Articles in C++ Programming:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!