Skip to content

Instantly share code, notes, and snippets.

@ravikiran0606
Created July 27, 2016 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravikiran0606/28b5d29deca36cc0a44366ee695cce3a to your computer and use it in GitHub Desktop.
Save ravikiran0606/28b5d29deca36cc0a44366ee695cce3a to your computer and use it in GitHub Desktop.
C++ Program to implement friend class and friend functions :
#include<iostream>
#include<string>
using namespace std;
class second{
private:
string a,b;
public:
second(string x,string y);
friend class first;
};
class first{
public:
void firstname(second);
void secondname(second);
};
second::second(string x,string y){
a=x;
b=y;
}
void first::firstname(second s){
cout<<"\nYour first name is "<<s.a<<endl;
}
void first::secondname(second s){
cout<<"\nYour second name is "<<s.b<<endl;
}
int main()
{
string a,b;
cout<<"Enter your Name : ( First Name followed by second Name )\n";
cin>>a>>b;
second obj(a,b);
first temp;
temp.firstname(obj);
temp.secondname(obj);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment