Created
July 27, 2016 15:46
-
-
Save ravikiran0606/28b5d29deca36cc0a44366ee695cce3a to your computer and use it in GitHub Desktop.
C++ Program to implement friend class and friend functions :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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