C++ Friendship - Indeed What's It ... ?: Saket Kr. Pathak Software Developer 3D Graphics
C++ Friendship - Indeed What's It ... ?: Saket Kr. Pathak Software Developer 3D Graphics
void Gal::disp() //Member Function definition { printf("\n%s\n", str_Nam_mood.c_str()); } Here our dear friend my_Guy(,) function changing the mood of his Gal ... ;). As conceptual point of view function has the access to private members of class and It can't be said as the member function, because friend function can't be accessed by scoperesolution, dot or arrow operators with class. void my_Guy(Gal &my_friend, std::string str_what_happn) //Friend Function Definition { my_friend.str_Nam_mood = str_what_happn; } Let's have main function regarding this Gal class. int main() { Gal aGal; aGal.disp(); my_Guy(aGal, "Have some Ferrero Rocher and Let's go Agra to see Taj!"); aGal.disp(); } //****
Page 3
void Gal::disp() { printf("\n%s\n", str_Nam_mood.c_str()); } Let's see how this class takes care of his friend who has given him complete access. He feels all the happiness that the Gal - class can imagine ... :) //___Class as a Man class Guy { public: Guy(); virtual ~Guy(); void please_change_ur_mood(Gal &dear_friend, std::string outing); }; Guy::Guy()
Saket Kr. Pathak
//Constructor
Page 4
void Guy::please_change_ur_mood(Gal &dear_friend, std::string str_what_happn) { dear_friend.str_Nam_mood = str_what_happn; } Now main() playing as the role of life and have a definition as, int main() { Gal aGal; aGal.disp(); Guy aGuy; aGuy.please_change_ur_mood(aGal, "Let's marry again and We will visit to Rome, this time!"); aGal.disp(); return 0; } Now that's a friend having complete trust and in-dependency with all the prospective views of respect and so, ... :) ... I LOVE IT ... :) haaa haa haaa :). Hmmm :) as per principle's of the concept, we need to notice a few points as; Friendship is not mutual unless explicitly specified. (i.e. If you dont introduce her/him to your friends, then she/he is just stranger for them and I remember a song "Don't talk to the Strangers ... Don't talk the Strangers ... Strangers Strangers" ... :) ) Friendship is not inherited. So, Inheritance stands outside here ... :) Friendship is not transitive. (It's not mandatory that, your friend will has to be a friend of your mate.) That's why I like C++. :) Ok so I don't think, It's needed to say It's completely my Prospective view to the concept which may vary from you. So don't be personal, enjoy it ... at least try ... :) Same as always take care in someone's style not mine, i used say catch you again :)
Page 5