SlideShare une entreprise Scribd logo
1  sur  5
Télécharger pour lire hors ligne
2011


 Saket Kr. Pathak
 Software Developer
 3D Graphics




[C++ Friendship - Indeed what's it ...?]
 A quick review of fundamentals of C with an prospective view of implementation in daily day
to day life.
C++ Friendship - Indeed what's it...?

A few days back I was thinking, what is Friendship and who is the Friend
Indeed. I was really a bit puzzled about the real definition and the practical
implementation of Friendship in our Daily life.

Trust me :) this is quite dangerous word for me and if I will be bit specific then, I never-
ever understand the meaning and sense, when a prefix added with this dangerous word
and it becomes "Healthy Friendship" haa haa haa :). Most of the time I had seen gals
using it ... :)

I thought to look for the antonyms of "Healthy Friendship", because sometimes
antonyms give a hazy sense to understand the actual word. So, i surfed hard around all
big search engine as Google, Bing and Alta-Vista for "Unhealthy Friendship" but as the
result, completely failed ... :( . Then after all when every door i knocked didn't open ... :),
then I came to my dearest C++ and felt the actual implementation of word "Friend" with
complete sense.

What we call friend in our life is not the actual sense of Friend, because Friend has
access to all the Private things/matters or hasn't any restriction and I am dead sure
there is no-one who share their all private stuff/matters with any single one throughout
life. ohhhooo hooo hooo :) Here I am talking about singles as i don't have any experience
of doubles or about further steps of life.

Before commenting here or blaming me wrong, think a minute and then decide. What ...
Parents ...(***knows everything just till your school days), then What ... College
time fiends ...(***common it's teen age yaar haaa :) haa :), and every one
among us knows each other well ... ;) ), then comes ... Office Colleges ... (***ask
them, if they have free time after being jealous ... ?).

But after everything there is a relationship which can be said as Friendship, if and only if
they are ideal. That's we are going to consider as my example. Let's See .... (of-course
copy-past of snippet will work this time) ...

Friend Functions (syntax C++)

//____Class as a Lady
class Gal
{
    private:
        std::string str_Nam_mood;
    public:
        Gal();
        virtual ~Gal();
        void disp();

     //Friend - Function to access Private Members

Saket Kr. Pathak                                                                         Page 2
C++ Friendship - Indeed what's it...?

    friend void my_Guy(Gal &my_friend, std::string
str_what_happn);
};

Here in our class "Gal" has a friend as function, :) named as my_Guy(,). Whenever he
meets the gal and when she became sad, he changes her mood ... ;) (***execute this if
you want to see how ?)

Gal::Gal():            //Constructor
str_Nam_mood("I not feeling good :("){}

Gal::~Gal(){}                     //Destructor

void Gal::disp()         //Member Function definition
{
    printf("n%sn", 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 scope-
resolution, 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();
}
//****




Saket Kr. Pathak                                                                   Page 3
C++ Friendship - Indeed what's it...?

Friend Class (syntax C++)

Here for explaining friend-class, Yes I am going to take help from previous example with
some addition. So, there will be a forward declaration of a class who is the friend of our
previous class as;

class Guy;

Then a bit change in Gal class as;

//____Class as a Lady
class Gal
{
    friend class Guy;             //friend class as a Soulmate
    private:
        std::string str_Nam_mood;
    public:
        Gal();
        virtual ~Gal();
        void disp();
};
Gal::Gal():             //Constructor
str_Nam_mood("I not feeling good :(")
{}

Gal::~Gal()                     //Destructor
{}

void Gal::disp()
{
    printf("n%sn", 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()                    //Constructor

Saket Kr. Pathak                                                                    Page 4
C++ Friendship - Indeed what's it...?

{}

Guy::~Guy()                     //Destructor
{}

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 don’t 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 :)



Saket Kr. Pathak                                                                      Page 5

Contenu connexe

En vedette

Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ opt
deepakskb2013
 
Oops practical file
Oops practical fileOops practical file
Oops practical file
Ankit Dixit
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
Hadziq Fabroyir
 

En vedette (20)

Inheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ optInheritance chapter-6-computer-science-with-c++ opt
Inheritance chapter-6-computer-science-with-c++ opt
 
A Guy and gal in STL
A Guy and gal in STLA Guy and gal in STL
A Guy and gal in STL
 
14. Linked List
14. Linked List14. Linked List
14. Linked List
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 
Copy constructor
Copy constructorCopy constructor
Copy constructor
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
1. Overview of Java
1. Overview of Java1. Overview of Java
1. Overview of Java
 
C++ diamond problem
C++ diamond problemC++ diamond problem
C++ diamond problem
 
Oops practical file
Oops practical fileOops practical file
Oops practical file
 
GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?GNU GCC - what just a compiler...?
GNU GCC - what just a compiler...?
 
Wan Important Questions
Wan Important QuestionsWan Important Questions
Wan Important Questions
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)Object-Oriented Design: Multiple inheritance (C++ and C#)
Object-Oriented Design: Multiple inheritance (C++ and C#)
 
C++ Template
C++ TemplateC++ Template
C++ Template
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Strings
StringsStrings
Strings
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance#OOP_D_ITS - 6th - C++ Oop Inheritance
#OOP_D_ITS - 6th - C++ Oop Inheritance
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 

Dernier

Dernier (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 

C++ friendship

  • 1. 2011 Saket Kr. Pathak Software Developer 3D Graphics [C++ Friendship - Indeed what's it ...?] A quick review of fundamentals of C with an prospective view of implementation in daily day to day life.
  • 2. C++ Friendship - Indeed what's it...? A few days back I was thinking, what is Friendship and who is the Friend Indeed. I was really a bit puzzled about the real definition and the practical implementation of Friendship in our Daily life. Trust me :) this is quite dangerous word for me and if I will be bit specific then, I never- ever understand the meaning and sense, when a prefix added with this dangerous word and it becomes "Healthy Friendship" haa haa haa :). Most of the time I had seen gals using it ... :) I thought to look for the antonyms of "Healthy Friendship", because sometimes antonyms give a hazy sense to understand the actual word. So, i surfed hard around all big search engine as Google, Bing and Alta-Vista for "Unhealthy Friendship" but as the result, completely failed ... :( . Then after all when every door i knocked didn't open ... :), then I came to my dearest C++ and felt the actual implementation of word "Friend" with complete sense. What we call friend in our life is not the actual sense of Friend, because Friend has access to all the Private things/matters or hasn't any restriction and I am dead sure there is no-one who share their all private stuff/matters with any single one throughout life. ohhhooo hooo hooo :) Here I am talking about singles as i don't have any experience of doubles or about further steps of life. Before commenting here or blaming me wrong, think a minute and then decide. What ... Parents ...(***knows everything just till your school days), then What ... College time fiends ...(***common it's teen age yaar haaa :) haa :), and every one among us knows each other well ... ;) ), then comes ... Office Colleges ... (***ask them, if they have free time after being jealous ... ?). But after everything there is a relationship which can be said as Friendship, if and only if they are ideal. That's we are going to consider as my example. Let's See .... (of-course copy-past of snippet will work this time) ... Friend Functions (syntax C++) //____Class as a Lady class Gal { private: std::string str_Nam_mood; public: Gal(); virtual ~Gal(); void disp(); //Friend - Function to access Private Members Saket Kr. Pathak Page 2
  • 3. C++ Friendship - Indeed what's it...? friend void my_Guy(Gal &my_friend, std::string str_what_happn); }; Here in our class "Gal" has a friend as function, :) named as my_Guy(,). Whenever he meets the gal and when she became sad, he changes her mood ... ;) (***execute this if you want to see how ?) Gal::Gal(): //Constructor str_Nam_mood("I not feeling good :("){} Gal::~Gal(){} //Destructor void Gal::disp() //Member Function definition { printf("n%sn", 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 scope- resolution, 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(); } //**** Saket Kr. Pathak Page 3
  • 4. C++ Friendship - Indeed what's it...? Friend Class (syntax C++) Here for explaining friend-class, Yes I am going to take help from previous example with some addition. So, there will be a forward declaration of a class who is the friend of our previous class as; class Guy; Then a bit change in Gal class as; //____Class as a Lady class Gal { friend class Guy; //friend class as a Soulmate private: std::string str_Nam_mood; public: Gal(); virtual ~Gal(); void disp(); }; Gal::Gal(): //Constructor str_Nam_mood("I not feeling good :(") {} Gal::~Gal() //Destructor {} void Gal::disp() { printf("n%sn", 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() //Constructor Saket Kr. Pathak Page 4
  • 5. C++ Friendship - Indeed what's it...? {} Guy::~Guy() //Destructor {} 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 don’t 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 :) Saket Kr. Pathak Page 5