Subscribe Us

Responsive Advertisement

Advertisement

friend function in oop c++

 

friend function in oop c++ part 1



#include<bits/stdc++.h>

using namespace std;

class item

{

    int dis;

public :

    void setval()

    {

        dis=10;

    }

    void display()

    {

        cout<<dis<<endl;

    }

     friend int newval(item &b);

};

int newval(item &b)

{

    b.dis=50;

}

int main()

{

    item a;

    a.setval();

    a.display();

    newval(a);

    a.display();

    return 0;

}


Post a Comment

0 Comments