Friend function

 avatar
narendra
c_cpp
a month ago
255 B
3
Indexable
#include <iostream>
using namespace std;

class A{
  int x ;
public:
   A (int y ){
  x = y;
  }
 friend void print(A &obj );
  
};
void print (A &obj){
  cout<<obj.x<<endl;
}

int main(){
  A obj(5);
  //cout<<obj.x<<endl;
  print (obj);
  
  return 0;
}
Leave a Comment