Friend Classes & Member Friend Functions in C++ | C++ Tutorials for Beginners #27

Поділитися
Вставка
  • Опубліковано 14 лис 2024

КОМЕНТАРІ • 507

  • @rahulsaroha8724
    @rahulsaroha8724 3 роки тому +175

    This type of content is only possible when you know the true goal of your life.

  • @shubhgupta7876
    @shubhgupta7876 3 роки тому +35

    code with harry is far better than apna college

  • @damanpreetsingh8389
    @damanpreetsingh8389 3 роки тому +226

    Overview of this and previous video:-
    In previous video, we declared a function outside class and that function tried to access the members of class which is not possible. So we declared the function friend.
    In this video, we made 2 classes with their respective functions and the members/functions of one class tried to access the members of other class which is not possible. So we declared the members of one class the friend of other class or we can declare the whole class friend of other class.
    Rest is syntax which we need to understand.

    • @zikrerasul7021
      @zikrerasul7021 2 роки тому +6

      thanks, summed it up perfectly

    • @damanpreetsingh8389
      @damanpreetsingh8389 2 роки тому +1

      @@zikrerasul7021 my pleasure ;)

    • @anwesh07
      @anwesh07 2 роки тому +1

      Why "add" function is not made friend of "Complex" class.....bcoz it is also trying to access the private members of "Complex" class????

    • @damanpreetsingh8389
      @damanpreetsingh8389 2 роки тому +9

      @@anwesh07 'add' function is not trying to access the variables a & b in Complex class bcoz they have same name but they are stored in different memory location.
      Let us say if you have a class A with variable 'int a' in private & a function to set and display for 'a'. Now there is a function outside the class to display 'a' as well. In the parameter if you will write (int a) and {cout

    • @sidhlover25
      @sidhlover25 Рік тому

      @@anwesh07 no

  • @zohaibafridi
    @zohaibafridi 2 роки тому +41

    You are one of the best programming teacher on UA-cam. Everywhere your name on the top in Programming.
    Thanks a lot.

  • @altamashsabri8142
    @altamashsabri8142 4 роки тому +183

    best tutorial on c++ literally

  • @mohammadadnanofficial
    @mohammadadnanofficial 4 роки тому +62

    I want some practice questions for this tutorial

  • @zulquarnainansari4471
    @zulquarnainansari4471 4 роки тому +125

    For every 12 hours a day , I am watching your video....

  • @indrajeetpatil3589
    @indrajeetpatil3589 2 роки тому +12

    //distance betwwen two points in coordinates system
    #include
    #include
    #include
    #include
    #include
    using namespace std;
    class Coordinates;
    class Distance{

    public:

    double Sqrt(Coordinates, Coordinates);

    };

    class Coordinates{

    double a,b;
    public:

    void setNum(double x, double y){
    a=x;
    b=y;
    }



    friend class Distance;

    };

    double Distance :: Sqrt(Coordinates o1, Coordinates o2){


    double sum=((o2.a-o1.a)*(o2.a-o1.a)+(o2.b-o1.b)*(o2.b-o1.b));
    return sqrt(sum);

    }

    int main()
    {
    Coordinates o1;
    Coordinates o2;
    o1.setNum(1,0);
    o2.setNum(1,0);

    Distance calc;

    double res = calc.Sqrt(o1,o2);
    cout

  • @riseabovehate1892
    @riseabovehate1892 4 роки тому +11

    You are one of the best coding teacher in INDIA

  • @behzadarif99
    @behzadarif99 4 роки тому +4

    You are very good teacher
    Maine aaj tak aapke jaisa koi teacher nahi dekha youtube par bhi aur kahi bhi
    Sachme aap ki padhane ki technic bahtreen hai 👌👌👌❤️❤️❤️❤️

  • @koushik7604
    @koushik7604 3 роки тому +18

    brushing up my programming knowledge ... it's really good! Thank you!

    • @artishsharma7859
      @artishsharma7859 3 роки тому +2

      Why he is declaring calculator before complex plz explain

    • @FANSasFRIENDS
      @FANSasFRIENDS 3 роки тому +4

      @@artishsharma7859 Well as far as I could understand , he here declared calculator class before complex class which does not has a specific reason so if u do not wish to change the position of the class then u can do so but then u will have to Forward declare the Calculator class instead of Complex class, rest same.

  • @mohdaadil6204
    @mohdaadil6204 2 роки тому +6

    The course is very helpful especially for beginners, your way of explaining is very awesome and unique. I love this course.

  • @nitametkar
    @nitametkar 2 роки тому +8

    Harry love your way of teaching this might take me to excellence in coding
    🤩

  • @AmanKhan-lj3wh
    @AmanKhan-lj3wh 2 роки тому +8

    lost a bit in between the video but till the end of video you cleared all the doubts
    Thanks a lot for the whole series man

  • @arpanchowdhury5133
    @arpanchowdhury5133 4 роки тому +30

    Topic :Competitive programming , please make video how much it is necessary and how can we continue it with development. Thank you.

    • @bussasunitha1876
      @bussasunitha1876 10 місяців тому +1

      Bro can u please tell me what topics should we learn to do problems of rating 1500 to 1800 in codechef

  • @anmolagrawal7307
    @anmolagrawal7307 3 роки тому +5

    great learning from you literaly you make the tutorial very intresting without investing a single money

  • @EnglsihCommByNawaz
    @EnglsihCommByNawaz 3 роки тому +18

    Ohhh my god! Really Harry sir to declare entire class as a friend is really amazing!

  • @ishanmusic677
    @ishanmusic677 8 місяців тому

    we can also do like--
    (for checking greater number in 2 classes)
    class A{
    int a;
    //here we have declared the function as a frind funtion
    friend check(int a,int b);
    public:
    void read(int val1){
    a=val1;
    }
    };
    class B{
    int b;
    friend check(int a,int b);
    public:
    void read(int val2){
    b=val2;
    }
    void check(int a, int b){
    if(a>b){
    cout

  • @sakalagamingyt3563
    @sakalagamingyt3563 2 роки тому +5

    /*
    By Bishal jaiswal
    Purpose : Practicing (friend class);
    */
    #include
    #include
    using namespace std;
    class X
    {
    int x1, x2;
    friend class Result;
    public:
    void setVal_X()
    {
    cout > x2;
    cout > x1;
    }
    };
    class Y
    {
    int y1, y2;
    friend class Result;
    public:
    void setVal_Y()
    {
    cout > y2;
    cout > y1;
    }
    };
    class Result
    {
    float actualDistance;
    public:
    void printDistance(X o1, Y ob1)
    {
    actualDistance = sqrt((o1.x2 - o1.x1) * (o1.x2 - o1.x1) + (ob1.y2 - ob1.y1) * (ob1.y2 - ob1.y1));
    cout

  • @mohtishammuzzammil9084
    @mohtishammuzzammil9084 3 роки тому +4

    ONE OF THE BEST TEACHERS I THINK

  • @alpeshmakwana3497
    @alpeshmakwana3497 3 роки тому +5

    Sir, this tutorial is very helpful for me.👍🏻👍🏻

  • @prathu7644
    @prathu7644 3 роки тому +6

    Thank you for your amazing content Harry bhai it helps a lot!!

  • @Shivangidev2022
    @Shivangidev2022 3 роки тому +2

    Superb class.... U r best programming teacher

  • @girrajkushwah182
    @girrajkushwah182 3 роки тому +1

    harry bhai bhut achcha se samjh me aa rha h or pdne me mza bhi aa rha h
    thanks for this................
    love from GWAIOR (MADHYA PRADESH)

  • @tejashwinihosur1712
    @tejashwinihosur1712 2 роки тому +1

    The best best tutor I ever got...🙏🏻✨💫

  • @dhanasrikanisetti2263
    @dhanasrikanisetti2263 3 місяці тому

    finally samajh agaya sir it is something tricky to understand !!!

  • @moviesbuddy4228
    @moviesbuddy4228 2 роки тому +3

    Bhai main cheez thank u so much for zooming the program while typing ... Whenever the size is small it's difficult to see .. but next moment u zoom (ctrl +) it and u make everything easy , enjoyable and intresting ...❤️❤️❤️❤️👍👍🙏
    Thank u so much

  • @saurabhniley5441
    @saurabhniley5441 Рік тому

    thank you for teaching in such a natural way

  • @DarkWorld0000
    @DarkWorld0000 2 роки тому +3

    Alot of love from 🇵🇰🇵🇰🇵🇰

  • @ManojKumar-wi2dn
    @ManojKumar-wi2dn 3 роки тому +19

    Nice video.But you didn't tell that why you placed calculator class above the complex class at time of error (at 5: 50). Because in stating we don't have to declare complex class at top and sum real function at bottom.And I got all points other than this and thanks for videos

    • @happysangwan4890
      @happysangwan4890 3 роки тому

      ya i also has same doubt. If u know now , then plz tell me.

    • @prateekkosta4758
      @prateekkosta4758 3 роки тому

      same doubt pls tell me

    • @katikalyani9107
      @katikalyani9107 2 роки тому +3

      By mistake he declared calculator class first,after that complex class. but in calculator class we have complex class as a datatype in one function which is not declared yet.So just declared complex class before calculator so that he doesn't get errors .
      Without re declaration you can just write calculator class after complex class.But sir explained alternative way if we don't want to change position of code.
      I guess 😀

    • @abhikgupta9312
      @abhikgupta9312 2 роки тому +7

      It's because when declaring the friend functions, for scope resolution you obviously need to write thr name of the class calculator... And there the compiler will throw an error.. So it needs to be declared first.

    • @Ayush_gupta0001
      @Ayush_gupta0001 Рік тому

      because compile don't know what is sumrealcomplex, it we define calculator class below complex class it gives error
      .

  • @techwithpanwar1507
    @techwithpanwar1507 3 роки тому +1

    Best programming teacher on youtube.

  • @than0s869
    @than0s869 2 роки тому +2

    Harry bhai me to friend class ka concept bilkul bhi nhi janta tha but aapne bata diya, thank you 😊

  • @Technical_Ninja
    @Technical_Ninja 2 роки тому +1

    Tume complexe number example use karke program understand bohot complex kr di

  • @shreyashkashyap
    @shreyashkashyap 2 роки тому +3

    As always, AWESOME!

  • @ratnakantahanse2661
    @ratnakantahanse2661 4 роки тому +1

    Thank you so much ..... God will always help you .... For your kindness.......

  • @vanshmehta8091
    @vanshmehta8091 2 роки тому +2

    I guess in class calculator
    We wrote int add(int a, int b){
    return (a+b);
    is not really used to in program
    Also print function of class complex is not used . It can be used very well for smooth output and clearance.
    i wrote this comment after doing this lecture and practical experience.
    apologize if I'm wrong. My aim is not to provide any wrong info to anyone.

    • @UdyamAbhi
      @UdyamAbhi Рік тому

      you said the right thing

  • @uttamkarmakarece3534
    @uttamkarmakarece3534 3 роки тому +2

    Thank you Harry bhaiya for this kind of amazing videos

  • @AshutoshKumar-fu6qe
    @AshutoshKumar-fu6qe 3 роки тому +69

    Google Ads : Are you interested in learning c- language?
    .......
    Me: No, I am interested in learning c-language from harry bhai.

  • @LofiAniFams
    @LofiAniFams 2 роки тому +2

    this is so much complicated but finally i cleared it because i see this video 2,3 times atleast

  • @anubhavakaxperience762
    @anubhavakaxperience762 3 роки тому +1

    Wow u explained it so good..like literally so good.thank u very much....

  • @ashutoshranjan4644
    @ashutoshranjan4644 Рік тому

    c++ is amazing. It provides those things which are out of syllabus for java.

  • @Sanchi_125
    @Sanchi_125 2 роки тому

    Just amazing, I am from westBengal👌👌👌

  • @the_uncommonman
    @the_uncommonman 4 роки тому +1

    Harry bhai your explanation are smooth as butter

  • @kevaldonga6384
    @kevaldonga6384 3 роки тому +1

    I understood full concept in one go

  • @cartoonsondemand_
    @cartoonsondemand_ 4 роки тому +1

    Best explanation forever thanks for your big help

  • @satyamkushwaha7385
    @satyamkushwaha7385 3 роки тому +1

    Thank you so muchh sir!❤❤😍😎

  • @al-baghdadi7914
    @al-baghdadi7914 4 роки тому +1

    this video is going very complex to me

  • @ShivamMishra-xd8nn
    @ShivamMishra-xd8nn 6 місяців тому +1

    see despite of just forwarding declaration of complex class above than calculator class . We select to define the complex class and then calculator class. In this way we have full definition of complex class so we can access it directly in calculator function. Isn't it??

  • @abdullahalhuzaifi5244
    @abdullahalhuzaifi5244 6 місяців тому

    Awesome content and very easy to understand............

  • @niranjangupta8644
    @niranjangupta8644 2 роки тому

    Bro you teach us from C++ E Balagurysamy book but your teaching skill is effective and excellent.Thnak you

  • @anshpradhan1954
    @anshpradhan1954 3 роки тому +1

    Thank u Harry Sir 🙏

  • @rajatshukla2605
    @rajatshukla2605 2 роки тому

    Great Explanation. Thanks for the video!

  • @mokshdharasharma5275
    @mokshdharasharma5275 4 роки тому +3

    You are a gem!!!!!!💟

  • @IDK-sk2yj
    @IDK-sk2yj 2 роки тому

    phalana and dhimana was O P... though that friend's class topics were easy to understand, and it was due to your explanation!

  • @Mazakare98
    @Mazakare98 2 роки тому

    Sir ji you r great thank u... 🌟

  • @paragroy5359
    @paragroy5359 3 роки тому +1

    Nice explanation your videos are really good...please keep on making such videos.

  • @JustwaitNwatch-w
    @JustwaitNwatch-w 2 роки тому +1

    15:50 bro i am not even surprised by this i can understand ke aapke andar ladoo foot rahe the uss time 🤣
    btw good tutorials

  • @Ri-wan
    @Ri-wan 2 роки тому +1

    Very helpful for us😊

  • @nirmalpurigoswami5253
    @nirmalpurigoswami5253 3 роки тому +3

    14:15 sum dhimaka complex😂😂

  • @nirmalpurigoswami5253
    @nirmalpurigoswami5253 3 роки тому +1

    Please make a video about c++ projects

  • @victorb22622
    @victorb22622 6 місяців тому

    9:21 हैरी की बातो से ऐसा लगता है जो फनी वे में बात करु तो , कोई आदमी, एक एक करके पकोड़े बनाने की रेसिपी बताता हो ,और बीच बीच में कहे की ये चीज याद रखो ,ये याद रखो ।जब हम पूछे की भाई पकोड़े की रेसिपी क्यू याद रखे हमे तो चाय बनानी है ,तो फिर वो कहेगा ,वो ठीक है लेकिन अभी ये पकोड़े की रेसिपी याद कर लो काम आयेगी।

  • @aniruddahpaul5537
    @aniruddahpaul5537 Рік тому

    This video is definitely one of the toughest ones I've come across so far.

  • @saarthakmishra5109
    @saarthakmishra5109 11 місяців тому +1

    Course sach mein bahut achha hai, but views ka difference dikh raha hai first video aur current video mein...bohot log quit kr dete hai

  • @sasuke3737
    @sasuke3737 3 роки тому

    i know all these but theres always smthing new u would learn from his video.

  • @abrarahmad3897
    @abrarahmad3897 Рік тому

    Hey harry, I just wrote the code for making an entire class as a friend and that's the code below, kindly check it and suggest some improvements:
    code:
    #include
    using namespace std;
    // creating a class complex to handle the complex numbers
    class complex; // by forward slashing
    // creating a class calculator to handle the mathematical functions
    class calculator{
    public:
    void sumcomplex(complex c1,complex c2); // by forward slashing
    };
    // defining the complex class over here
    class complex{
    int a,b;
    public:
    void setnumber(int x,int y);
    // making an entire class as a friend
    // all functions of the class calculator can now access the private data of the class complex
    friend class calculator;
    };
    void complex :: setnumber(int x , int y){
    a = x;
    b = y;
    cout

  • @garvittyaginawla4577
    @garvittyaginawla4577 Рік тому

    THANKS 🙏 HARRY BHAIYA
    FOR AMAZING VIDEOS

  • @yashdongre1752
    @yashdongre1752 3 роки тому +1

    Thanku bhaiya

  • @tuntunewala
    @tuntunewala 3 роки тому +1

    1st time it did'nt clear so much but after watching the lecture 2nd time , all clear good work harry bhai>

  • @farzanayeasminsumana4426
    @farzanayeasminsumana4426 2 роки тому +1

    Good one

  • @abhayupparwal3888
    @abhayupparwal3888 2 роки тому

    Enjoying your video.
    Thank you

  • @Rohit-rt1lx
    @Rohit-rt1lx 3 роки тому

    Harry bhai, you are such a genius 👍

  • @PlayLikePro327
    @PlayLikePro327 3 роки тому +1

    Sir mujhe kuch nhi ata tha c++ ..but ab bhut kuch aane laga h but..... practice ke liye concepts se related hw chahiye .....plx

  • @mehndi.6236
    @mehndi.6236 Рік тому

    Thank you sir 🙏🙏

  • @nikhilsarkar3657
    @nikhilsarkar3657 3 роки тому +1

    LOVE YOU HARRY BHAI!!!

  • @tanmayshingote3335
    @tanmayshingote3335 3 роки тому

    Harry hai to sab mumkin hai 😀❤️❤️

  • @engineerbhai7642
    @engineerbhai7642 4 роки тому +1

    Thanks.

  • @YouTubeSupporters
    @YouTubeSupporters 4 роки тому +4

    Bhi aap he batlay the agar declear kr rhe to ushke under ::--->
    (complex o1 , complex o2);
    Yha -> o1 ,o2. likeh ya nahi likhe koi farq nahi pdega.

  • @prakharparsai4758
    @prakharparsai4758 Рік тому

    sir app boilerplate jaisi tips and tricks short form mein kaat ke upload kardo easy ho jayega for people to find out

  • @learncode6180
    @learncode6180 3 роки тому +1

    Best course ❤️🙏

  • @Sujit_Badgujar
    @Sujit_Badgujar 3 роки тому

    @CodeWithHarry bhai code likhte vaqt zoom kiya karo, bahot badiya kam hoga

  • @alphagaming8414
    @alphagaming8414 3 роки тому

    Thankyou, it helps.

  • @sanketsbrush
    @sanketsbrush 7 місяців тому

    Boilerplate video is worth watching. It saves lot of time

  • @fassimaryam1405
    @fassimaryam1405 2 роки тому

    Thankyou Soo much 💙

  • @ananddesai9020
    @ananddesai9020 3 роки тому +8

    4 time dekha Video ko Tab Jaake Samjha Mara Dimag Mujhse Kehta hain : kya Programmer banega re Tu 😔

    • @kushal6065
      @kushal6065 3 роки тому

      same😂😂😥

    • @akshaysatyam2
      @akshaysatyam2 3 роки тому

      I know few people who don't even try to learn and call themselves future programmers.

    • @ananddesai9020
      @ananddesai9020 3 роки тому

      So what can do guys 😥

    • @kushal6065
      @kushal6065 3 роки тому

      Of course programming is hard. It's definitely not an easy task. But you have to learn it every day without skipping a day and constantly grind yourself then you will understand little by little everyday. c++ is quite hard than other languages like python, javascript,etc. So don't give up yet.

    • @mahadevjagtap4640
      @mahadevjagtap4640 3 місяці тому

      ​@@ananddesai9020kya hua bhai bane ki nahi programmer

  • @firenub
    @firenub Рік тому

    great course

  • @manojverma245
    @manojverma245 2 роки тому

    Thanks a lot ❤️❤️❤️❤️

  • @sanyamsharma350
    @sanyamsharma350 Рік тому

    this man is making these hard topics as easy as watching a intresting vine, one like for him 👍

  • @machindrachavan9263
    @machindrachavan9263 2 роки тому

    Thank YOu Harry Bhai .

  • @RohanDasRD
    @RohanDasRD 4 роки тому +17

    Classy Tutorial..

  • @AnsaAreej-zv7lk
    @AnsaAreej-zv7lk Рік тому

    Binary operator and operator overloading k lecture b provide kr dain

  • @shivakarthikrathod2026
    @shivakarthikrathod2026 3 роки тому +1

    I saw this vedio 5 times then I got understand

  • @vikashmaskhare3772
    @vikashmaskhare3772 4 роки тому

    You are great sir

  • @vrohan07
    @vrohan07 2 роки тому

    thank you bhaiya!!

  • @shubhsharma19
    @shubhsharma19 3 роки тому

    what a nice explanation bro

  • @akanksha3930
    @akanksha3930 4 роки тому +1

    Hi Harry, Please make video on Angular and React...………….

  • @haramshahid1149
    @haramshahid1149 2 роки тому

    sir binary search tree class (BST) k lie aik video bna den kindy... apki sari videos dekhti hn me... thanku so much hamary lie ap aitna sb krty hen... may Allah help you to achieve your goals ameen... binary search tree me ye friend class smjha den plzzzz...

  • @excel8280
    @excel8280 3 роки тому +5

    After finishing your C 15 hours tutorial within 30 days now watching this :)

    • @akashdeep2930
      @akashdeep2930 2 роки тому

      Was it helpful? Can I prefer watching that?

  • @ayushwalker2003
    @ayushwalker2003 3 роки тому

    Thank you so Harry bhaiya, for making such informational video..

  • @sabianajaffar8442
    @sabianajaffar8442 4 місяці тому

    you are great wallah

  • @simranbains6199
    @simranbains6199 2 роки тому

    thank you so much bro