Skip to main content

Friend Funciton

 




#include <iostream>



using namespace std;

class B;

class A{

    private:

    int a;

    public:

    void setData(int x){

        a=x;

    }

    friend void fun(A,B);

};

class B{

  private:

  int b;

  public:

  void setData(int y){

      b=y;

  }

  friend void fun(A,B);

};

void fun(A o1, B o2){

    cout<< "Sum is "<<o1.a + o2.b;

}

int main(){

    A obj1;

   

    B obj2;

     obj1.setData(5);

    obj2.setData(6);

    fun(obj1, obj2);

    

}

Comments

Popular posts from this blog

Get Free Hosting From Google Drive For Free

    Free Web Hosting with Google Drive  Google drives are the most widely used cloud storage all over the world. Google drives also can be used to host websites for free.  So first set up a google id which you most probably have. After you have done that follow the following ways: 1)copy all the required files to Google Drive. 2)Select all the required files and do the right click and click on select. 3)click on advance  4)change the private change 5)click on public on the web 6)Save it 7) Go to the site drv.tw  8)click on google drive 9)log in to gmail 10)From the admin panel select the index file or your main webpage 11) Congrats your hosted the website for free. 12)Thank you