FRIEND FUNCTION IN C++


#include<iostream>
using namespace std;
class abubakar{
public:
void setvalues(){
x=0;
}
void getvalues(){
cout<<"the value of x initially "<<x<<endl;
}
private:
int x;
friend void  changeX(abubakar &obj);
};

void  changeX(abubakar &obj){
obj.x=123;
cout<<endl<<"the value of x now is equal to "<<obj.x<<endl;
}
int main(){
abubakar obj;
obj.setvalues();
obj.getvalues();
changeX(obj);

}



Previous
Next Post »

Comments:

Disqus Shortname