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

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 พ.ย. 2024

ความคิดเห็น • 507

  • @rahulsaroha8724
    @rahulsaroha8724 3 ปีที่แล้ว +174

    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

  • @altamashsabri8142
    @altamashsabri8142 4 ปีที่แล้ว +183

    best tutorial on c++ literally

  • @zohaibafridi
    @zohaibafridi 2 ปีที่แล้ว +41

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

  • @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

  • @zulquarnainansari4471
    @zulquarnainansari4471 4 ปีที่แล้ว +125

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

    • @organafillic
      @organafillic 3 หลายเดือนก่อน

      syntax hai bhai

  • @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 👌👌👌❤️❤️❤️❤️

  • @mohammadadnanofficial
    @mohammadadnanofficial 4 ปีที่แล้ว +62

    I want some practice questions for this tutorial

  • @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

  • @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.

  • @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

  • @EnglsihCommByNawaz
    @EnglsihCommByNawaz 3 ปีที่แล้ว +18

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

  • @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

  • @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
    🤩

  • @than0s869
    @than0s869 2 ปีที่แล้ว +2

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

  • @anmolagrawal7307
    @anmolagrawal7307 3 ปีที่แล้ว +5

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

  • @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

  • @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)

  • @mohtishammuzzammil9084
    @mohtishammuzzammil9084 3 ปีที่แล้ว +4

    ONE OF THE BEST TEACHERS I THINK

  • @dhanasrikanisetti2263
    @dhanasrikanisetti2263 2 หลายเดือนก่อน

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

  • @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.

  • @alpeshmakwana3497
    @alpeshmakwana3497 3 ปีที่แล้ว +5

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

  • @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

  • @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

  • @tejashwinihosur1712
    @tejashwinihosur1712 2 ปีที่แล้ว +1

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

  • @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

  • @shreyashkashyap
    @shreyashkashyap 2 ปีที่แล้ว +3

    As always, AWESOME!

  • @saurabhniley5441
    @saurabhniley5441 ปีที่แล้ว

    thank you for teaching in such a natural way

  • @LofiAniFams
    @LofiAniFams 2 ปีที่แล้ว +2

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

  • @techwithpanwar1507
    @techwithpanwar1507 3 ปีที่แล้ว +1

    Best programming teacher on youtube.

  • @abdullahalhuzaifi5244
    @abdullahalhuzaifi5244 6 หลายเดือนก่อน

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

  • @Sanchi_125
    @Sanchi_125 2 ปีที่แล้ว

    Just amazing, I am from westBengal👌👌👌

  • @DarkWorld0000
    @DarkWorld0000 2 ปีที่แล้ว +3

    Alot of love from 🇵🇰🇵🇰🇵🇰

  • @satyamkushwaha7385
    @satyamkushwaha7385 3 ปีที่แล้ว +1

    Thank you so muchh sir!❤❤😍😎

  • @yashdongre1752
    @yashdongre1752 3 ปีที่แล้ว +1

    Thanku bhaiya

  • @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

  • @vrohan07
    @vrohan07 2 ปีที่แล้ว

    thank you bhaiya!!

  • @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 2 ปีที่แล้ว

      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
      .

  • @mehndi.6236
    @mehndi.6236 ปีที่แล้ว

    Thank you sir 🙏🙏

  • @the_uncommonman
    @the_uncommonman 4 ปีที่แล้ว +1

    Harry bhai your explanation are smooth as butter

  • @mokshdharasharma5275
    @mokshdharasharma5275 4 ปีที่แล้ว +3

    You are a gem!!!!!!💟

    • @artishsharma7859
      @artishsharma7859 3 ปีที่แล้ว

      Why he is declaring calculator before complex plz explain

    • @sidhlover25
      @sidhlover25 ปีที่แล้ว

      hi

  • @anshpradhan1954
    @anshpradhan1954 3 ปีที่แล้ว +1

    Thank u Harry Sir 🙏

  • @ashutoshranjan4644
    @ashutoshranjan4644 ปีที่แล้ว

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

  • @tanmayshingote3335
    @tanmayshingote3335 3 ปีที่แล้ว

    Harry hai to sab mumkin hai 😀❤️❤️

  • @fassimaryam1405
    @fassimaryam1405 2 ปีที่แล้ว

    Thankyou Soo much 💙

  • @ratnakantahanse2661
    @ratnakantahanse2661 4 ปีที่แล้ว +1

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

  • @anubhavakaxperience762
    @anubhavakaxperience762 3 ปีที่แล้ว +1

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

  • @abhayupparwal3888
    @abhayupparwal3888 2 ปีที่แล้ว

    Enjoying your video.
    Thank you

  • @Ri-wan
    @Ri-wan 2 ปีที่แล้ว +1

    Very helpful for us😊

  • @manojverma245
    @manojverma245 2 ปีที่แล้ว

    Thanks a lot ❤️❤️❤️❤️

  • @rajatshukla2605
    @rajatshukla2605 2 ปีที่แล้ว

    Great Explanation. Thanks for the video!

  • @Mazakare98
    @Mazakare98 2 ปีที่แล้ว

    Sir ji you r great thank u... 🌟

  • @kevaldonga6384
    @kevaldonga6384 3 ปีที่แล้ว +1

    I understood full concept in one go

  • @niranjangupta8644
    @niranjangupta8644 2 ปีที่แล้ว

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

  • @aniruddahpaul5537
    @aniruddahpaul5537 ปีที่แล้ว

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

  • @paragroy5359
    @paragroy5359 3 ปีที่แล้ว +1

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

  • @machindrachavan9263
    @machindrachavan9263 2 ปีที่แล้ว

    Thank YOu Harry Bhai .

  • @firenub
    @firenub ปีที่แล้ว

    great course

  • @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?

  • @himanshumandal7565
    @himanshumandal7565 2 ปีที่แล้ว +71

    pinky tum mera msg dekh rhi ho toh mujhko maaf kardo coding woding mere bas ka nhi.....shadi karke khus rehna kisior se kyu ki abba toh nhi manenge

    • @theflash34529
      @theflash34529 10 หลายเดือนก่อน +3

      Moye moye 😢😢

    • @ashwinverma2030
      @ashwinverma2030 10 หลายเดือนก่อน +6

      😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂 0:31

    • @littlenishad912
      @littlenishad912 10 หลายเดือนก่อน +1

      Bechari pinki

    • @Deepanshutyagi-q2m
      @Deepanshutyagi-q2m 10 หลายเดือนก่อน +1

      Bhai tum yai jajha mila ha ashki koo. Inti social media application haa bro

    • @vishalk568
      @vishalk568 10 หลายเดือนก่อน +1

      RIP Pinky 🎉

  • @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

  • @farzanayeasminsumana4426
    @farzanayeasminsumana4426 2 ปีที่แล้ว +1

    Good one

  • @cartoonsondemand_
    @cartoonsondemand_ 4 ปีที่แล้ว +1

    Best explanation forever thanks for your big help

  • @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>

  • @engineerbhai7642
    @engineerbhai7642 4 ปีที่แล้ว +1

    Thanks.

  • @Technical_Ninja
    @Technical_Ninja 2 ปีที่แล้ว +1

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

  • @garvittyaginawla4577
    @garvittyaginawla4577 ปีที่แล้ว

    THANKS 🙏 HARRY BHAIYA
    FOR AMAZING VIDEOS

  • @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!

  • @simranbains6199
    @simranbains6199 2 ปีที่แล้ว

    thank you so much bro

  • @zeeshanameer8
    @zeeshanameer8 9 หลายเดือนก่อน

    Well done boss😊

  • @nikhilsarkar3657
    @nikhilsarkar3657 3 ปีที่แล้ว +1

    LOVE YOU HARRY BHAI!!!

  • @al-baghdadi7914
    @al-baghdadi7914 4 ปีที่แล้ว +1

    this video is going very complex to me

  • @abhinavpandey2517
    @abhinavpandey2517 3 ปีที่แล้ว

    Thank you bhai 🙏

  • @mannnanshaikh7608
    @mannnanshaikh7608 3 ปีที่แล้ว +2

    Harry Sir ,
    You tech the c++ very well and i really appreciate your work.
    but i noticed that the videos are take too long to evaluate the small topic.
    so i really appreciate if u solve this issue and give us more content in future like this.
    Thanks in advance .

  • @sasuke3737
    @sasuke3737 3 ปีที่แล้ว

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

  • @RoronoaZoro_enma
    @RoronoaZoro_enma 2 ปีที่แล้ว +4

    It takes 2 days 50 time rewinding the video to understand the whole thing ❤️. Belive me he did his best nd did nothing wrong.

    • @firenub
      @firenub ปีที่แล้ว

      Real

  • @priyanshkashyap2993
    @priyanshkashyap2993 2 ปีที่แล้ว

    Thanks vro 👍👍

  • @alphagaming8414
    @alphagaming8414 3 ปีที่แล้ว

    Thankyou, it helps.

  • @learncode6180
    @learncode6180 3 ปีที่แล้ว +1

    Best course ❤️🙏

  • @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

  • @RohanDasRD
    @RohanDasRD 4 ปีที่แล้ว +17

    Classy Tutorial..

    • @anoopkumarshukla6808
      @anoopkumarshukla6808 4 ปีที่แล้ว +2

      Rohan Das ..Do you know sir personally ?? he has mentioned your name in many videos :)

    • @dangergamimg1933
      @dangergamimg1933 3 ปีที่แล้ว +3

      Omago rohan das mil gya.

    • @abhijitsingh9235
      @abhijitsingh9235 3 ปีที่แล้ว +3

      @@dangergamimg1933 😂😂😂

    • @programmingwithjavascript3579
      @programmingwithjavascript3579 3 ปีที่แล้ว +1

      Yahi hai rohandas iske Chanel par jaake dekho isne code with harry ko add rakha hai 😂😂😂

  • @abhishekojha523
    @abhishekojha523 4 ปีที่แล้ว

    Nice explanation

  • @shubhsharma19
    @shubhsharma19 3 ปีที่แล้ว

    what a nice explanation bro

  • @KoushikBhowmick-jp8jz
    @KoushikBhowmick-jp8jz ปีที่แล้ว

    Awesome ❤

  • @dalvinder_kaur
    @dalvinder_kaur 3 ปีที่แล้ว

    Thankyou sir ♥️

  • @MREleven11
    @MREleven11 2 ปีที่แล้ว

    amazing videos Harry Bhaiya !!!!!!!!

  • @Rohit-rt1lx
    @Rohit-rt1lx 3 ปีที่แล้ว

    Harry bhai, you are such a genius 👍

  • @sanyamsharma350
    @sanyamsharma350 ปีที่แล้ว

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

  • @samirshaikh6806
    @samirshaikh6806 4 ปีที่แล้ว

    good harry bhai ek number

  • @sanketsbrush
    @sanketsbrush 7 หลายเดือนก่อน

    Boilerplate video is worth watching. It saves lot of time

  • @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

  • @rushikeshsanap1981
    @rushikeshsanap1981 ปีที่แล้ว

    ❤️ thank you❤️

  • @yashwani8155
    @yashwani8155 2 ปีที่แล้ว

    love you sir!!!

  • @Lifeisgood108-33
    @Lifeisgood108-33 3 ปีที่แล้ว

    Harry bhai aap great ho 🙂

  • @ganeshkpawar9919
    @ganeshkpawar9919 ปีที่แล้ว

    Majjaa AAA Raha hai bhaiya ❤

  • @sabianajaffar8442
    @sabianajaffar8442 4 หลายเดือนก่อน

    you are great wallah