Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //48_friend
- /*
- friend of a class is sth. that totally separated
- from a class but still has access to the stuff of
- the class
- */
- #include <iostream>
- using namespace std;
- class StankFist {
- public:
- StankFist (){stinkyVar=0;}//consr. that set sV equal to 0
- ;
- private:
- int stinkyVar;
- friend void stinkysFriend (StankFist &sfo);//as a parameter takes &sfo StankFist object
- };// friend has access to all that stuff inside StankFist object
- // a class has to give away his friendship
- void stinkysFriend (StankFist &sfo) { //(bob)//shows where we takes a parametr
- sfo.stinkyVar=99;//using sfo (object) we have access to all functions and objects in class
- cout<<sfo.stinkyVar<<endl;
- }
- int main()
- {
- StankFist bob;//stinkyVar=0, because it's constructor
- stinkysFriend(bob);//stinkysFriend function takes StankFist object (sfo) as a parameter
- }
Advertisement
Add Comment
Please, Sign In to add comment