Friend functions and classes in C++ (Programming for beginners)

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

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

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

    📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
    C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
    Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
    🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
    Experience the power of practical learning, gain career-ready skills, and start building real applications!
    This is a step-by-step course designed to take you from beginner to expert in no time!
    💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
    Use it quickly, because it will be available for a limited time.
    Homework solution:
    #include
    #include
    #include
    using namespace std;
    class TH-camChannel {
    string Name;
    int SubscribersCount;
    public:
    TH-camChannel(string name, int subscribersCount) {
    Name = name;
    SubscribersCount = subscribersCount;
    }
    bool operator==(const TH-camChannel& channel) const {
    return this->Name == channel.Name;
    }
    friend ostream& operator

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

      I figured you'd have to use public access for much of the classes - otherwise I'd be making int main() a friend along with making the classes friends of each other, and even then I'd get an error with == operator being private due to a context of some sort of access inability in a template in a file called 'list.tcc'.
      I'm guessing my approach of not using public access at all would have been impossible?

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

    You are so amazing with this stuff, Saldina. I just completed my C++ for Engineers and Scientists class and nailed a 95.6% for the class. I owe at least part of that to your great videos. And now that I know classes, I can understand this topic which he never did in my class. Thank you!!!! 😀

  • @eric-jt
    @eric-jt 2 ปีที่แล้ว +6

    I come to your channel everyday to learn something new. Thanks!

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

      I'm happy to hear that, cheers 🥰🥰

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

    Finally found the ultimate teacher...
    So concrete and so useful. You're the best...

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

    Imas svoj stil, objasnjavas jasno i detaljno. Puno truda ulazes u svaki video i to se vidi. Hvala jos jednom.
    :)

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

    One of the most clear explaination of Friend function on the internet.

  • @sravankumpati6564
    @sravankumpati6564 10 หลายเดือนก่อน

    Hi, thank you for your outstanding videos. Very helpful and refreshing.
    In C++, a function can be designated as a friend of a class, allowing it to access the private and protected members of that class. This friendship can be established in three ways: a stand-alone function, a member function of another class, and a separate class.
    In your last example, you mentioned that a member function of another class cannot be declared as a friend. To clarify, it is indeed possible to declare a member function of another class as a friend. What was likely meant is that a member function of a class cannot be declared as a friend of the same class it belongs to.
    In the context of friend functions, the typical scenario is to declare a stand-alone function or a member function of another class as a friend of a class, enabling it to access the private and protected members of that class. If you need to provide friend access specifically for a member function of another class, you can achieve this by declaring the entire class as a friend, not just the individual member function.
    Would you please clarify?, thank you.

  • @sourabhsingh192
    @sourabhsingh192 7 หลายเดือนก่อน +1

    she cleared the concept very clearly, good work

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

    Hi Saldina, Can you please make a video on using friend classes with a forward declaration for the Google test without altering the source code?

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

    Awesome stuff, thank you for helping me brush up on my OOP skills.

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

    I choose to stay not only because you're amusing (haha) also because you explain the concepts very well, step by step and logically.

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

    we have not called PrintResults function yet, and walso we have to pass the et object as the parameter... God bless you!

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

    I am studying c++ for months and i couldnt understand anything and i was afraid of my midterm exam but i feel like i am starting to understand so thank you so much (ps: your diction is very good so i can understand easily even though i am not native in English and also you speak sincerely so I don't start daydreaming in class and I listen carefully :) . Thanks again)

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

      Please view Bro Code videos too. It's very detail course with real examples.

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

    Hi Saldina first of all, your videos are great and well explained, question, what is the differences between friends class and Inheritance what are the benefits of using friends over Inheritance?

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

    Thank You! You explained it way better than how my book tried to! 👍👍👍

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

    Thanks alot for these kinda outstanding videos, it means alot to me (student)

  • @lilgohan
    @lilgohan 10 หลายเดือนก่อน

    thank you for updating to dark mode

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

    Wholesome programming content indeed 😊

  • @franktan9937
    @franktan9937 6 หลายเดือนก่อน +1

    your lessons are great

  • @nastaranhendijani681
    @nastaranhendijani681 6 หลายเดือนก่อน +1

    thank you, very helpful!

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

    Instead of circumference it's called perimeter! Great videos thanks 👍

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

    Hi, Saldina! good morning according to Afghanistan Time Zone. thanks a lot from this lecture also i was a little bit worry about you because you wasn't present on your social media.so I wish from GOD to help you what something wrong happened with you to solve As soon As possible.

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

    best teacher😻🙂

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

    3:00 perimeter not circumference

  • @محمدسيدالكوميالكومي
    @محمدسيدالكوميالكومي 2 ปีที่แล้ว +1

    Please, could you explain a data structure type that is called a graph or tree Thank you very much

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

      Would you like me to link you some resources I've found helpful?

  • @ZiaurRehman-ex3of
    @ZiaurRehman-ex3of 5 หลายเดือนก่อน +1

    now printresult is not a global function
    that's why it give error

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

    // friend functions
    // #include
    // using namespace std;
    // class Triangle{
    // private:
    // int side_length, circum;
    // public:
    // void set_side(int a){
    // side_length=a;
    // circum=side_length*3;
    // }
    // friend void PrintResults(Triangle); //no need to specify parameter name....parameter type is enough
    // };
    // void PrintResults(Triangle obj){
    // cout

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

    what keyboard you are using, sounds fantastic

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

    Good job, thanks 👍

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

    4:10 I watched that part like 5 times... so cute haha

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

    Haha, 04:16 Brazilian meme --> Renata Sorrah brazilian actress!

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

    thanks

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

    really nice

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

    At 1:34, I saw public class MyBaseClass, how did you do that, I am also trying the same in my C++ 14 visual studio, it's not working, hoping to get your reply back.

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

    I love you more for your beauty and intelligence

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

    👏👏👏👏👏

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

    Ironically C++ all ready weakens encapsulation, so friend just further weakens it.
    C still #1 in encapsulation, all you see is your forward declarations in your header file and nothing more.
    C++ came along and put all the private variables in the header file🤦‍♂️, why?
    Their answer to the problem a hack private public friend
    Swift takes the biscuit tho, places implementation and declarations all in one single file 🤣🤪

  • @zero-ui1ew
    @zero-ui1ew 4 หลายเดือนก่อน

    Circumference of a triangle ?😂😂😂

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

    How can i give acces to operator+= with friend function ?
    This is my work so far:
    #include
    using std::string;
    using std::cout;
    using std::ostream;
    using std::endl;
    #include
    using std::list;
    class DigiTv { //1
    string NumeCanal;
    int NrPrivitoriFideli;
    friend ostream& operator>>(ostream&, DigiTv&); //5 //7
    public:
    DigiTv(string nume, int nrPrivitoriFideli) { //2
    NumeCanal = nume;
    NrPrivitoriFideli = nrPrivitoriFideli;
    }
    };
    ostream& operator>>(ostream& COUT, DigiTv& digiT) { //4 //7
    COUT

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

    A rule I was taught is this: "Friends let friends touch each other's privates."
    Gives "You got a friend in me" a whole new meaning.

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

    How to stop look to you and start look to code? hehe

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

    Can you please post a full detailed long video on below two topics:
    Data structures using C++
    STL using C++

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

    Hey Saldina, your lessons are greatt 😁. And one thing, I guess it's called perimeter, circumference is perimeter of circle...

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

    Thou shall not fall in love with your teacher 😭😭😭😭

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

      something similar ....... coincidence do happen wow.......

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

      disgusting

    • @dxshawn532
      @dxshawn532 11 หลายเดือนก่อน +1

      Victor are you saying you're gay?

    • @Якороче-ц1н
      @Якороче-ц1н 8 หลายเดือนก่อน +2

      Simp init

    • @zero-ui1ew
      @zero-ui1ew 4 หลายเดือนก่อน +3

      Nah u down bad

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

    When you finish making all the beginner videos, you should make some videos about Qt 6. It's more advanced and _way_ more capable, and it's relatively easy to use.
    Personally I love programming with Qt, since it just lets you do everything your way and it has a very deep connection with C++ (they "invented" a lot of the things in stdlib today like smart pointers etc...). I particularly find the concept of signals and slots amazing for multi-threaded programs. While it is mostly used to make GUI apps, you can also just make CLI programs that work really well.
    If you don't know anything about qt, then make it your new years resolution to learn it. I guarantee you won't regret it.
    Sretna nova godina!

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

    mam its my first time to watch your video .
    your explanation is great, thank you for this type of useful videos
    love from INDIA

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

    Another way, to have firend function,
    #include
    using namespace std;
    class Base;
    class BaseFriend {
    public:
    void printResult(Base& b);
    };
    class Base {
    private:
    float a;
    float power = 0;
    public:
    void setA(float l) {
    a = l;
    power = a * a;
    }
    friend void BaseFriend::printResult(Base&);
    };
    void BaseFriend::printResult(Base& b) {
    cout

  • @Ayush-qn7hy
    @Ayush-qn7hy 2 ปีที่แล้ว +4

    Saldina how about a code review series? We would love to send you our C++ projects 🙂 and would love your reaction on it.

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

    great video , love from South Africa

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

    You are the best teacher ever. Thanks for reminding me how beautiful programming is. *_*

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

    04:15 Fun fact, this meme isn't Julia Roberts

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

    9:40 - You forgot to call the function :D

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

    Thanks a lot for those awesome videos!! I used to learn C++ and it was too hard for me so I gave up. After watching your tutorials, your excellent and outstanding work has given me confidence in learning C++ and interest in programming again. You are an excellent teacher and a role model for me on the way to learning code. Now I think the code is really cool, I also hope to become a programmer one day. Thank you again for everything.

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

    You made my preparation for the exam easier and less stressful. Thank you for the good work!

  • @joonbeomkim9898
    @joonbeomkim9898 8 หลายเดือนก่อน +2

    I have watched three different videos of friend functions on TH-cam and you are absolutely the best. You explains in details why we need to use friend functions and when to use them. I subscribed you and will keep watch your videos! You're very talented teaching c++.

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

    Great Job! I learnt alot today, and I am grateful.🙂

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

    I finally understand them...thanks!

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

    Share it with your friends, but she told us to be careful to choose friends and friends don't inherit and friendship isn't mutual, so basically now I haven't friends to share it. 😔

  • @bubble_gum_witch
    @bubble_gum_witch 4 หลายเดือนก่อน +1

    thanks so much❤

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

    Thankyou saldina.

  • @Loki-vy5vg
    @Loki-vy5vg ปีที่แล้ว +1

    you said creating getters is not a good solution because, everyone would be able to excess the class variables using getters, but the same thing is true for a friend function also, everyone can still access them now using friend function.

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

    Great mam.
    Where are you from

  • @isaacl.quelemine8775
    @isaacl.quelemine8775 2 ปีที่แล้ว +2

    I ready do admire your teaching always
    You’re quite amazing 😻 .

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

    mam plzzzzzzzzzzzz 🙏🏽🙏🏽🙏🏽🙏🏽🙏🏽🙏🏽🙏🏽 make video on aggregation and composition in C++

  • @ahmadahmad-ug8ls
    @ahmadahmad-ug8ls 5 หลายเดือนก่อน +1

    u are a legend istg

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

    incredible work!

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

    at 4:16 she used a brazilian meme... I like this !!!

  • @sangeeth.47
    @sangeeth.47 8 หลายเดือนก่อน +1

    ❤ Really Appreciate the efforts... Explained a lot of better than teaching in my university.

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

    You used a Brazilian meme hahaha. I'm from Brazil. Excellent content, thank you.

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

    a problem with using friend functions is that they are not as optimizable or as self documenting as comprehensive getters & setters.

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

    Hello from Philippines!

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

    I'm in love with this channel, and even if I'm not fluent in english I can understand you pretty clearly.

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

    Hey, waiting for the premiere ,lots of appreciation and thanks for teaching us.

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

    Thank you so much for the videos. They are very helpful. The way you are explaining from basic level followed by intermediate level is very helpful. Also, please make the videos on advanced concepts and incorporating security measures (like buffer overflow) in C++ code. Also, kindly post videos very frequently.

  • @ferfykins
    @ferfykins 8 หลายเดือนก่อน +1

    Excellent explanation, ty so much!

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

    Hello, thank you for this great job. Could you please do a tutorial about modern C++ (like C++11 and more). Thank you in advance ☺️

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

    thank u very much princess

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

    now my class has more friends than me..

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

    Suspenseful stuff...absolutely blindsided by the area of triangle formula 🤣

  • @Kraboobee
    @Kraboobee 11 หลายเดือนก่อน

    I actually did stay because you are extremely amusing 😂

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

    Would it be possible to post .txt with your TH-cam videos, it would be easier to follow along?

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

    ❤️❤️❤️

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

    The reason it was blank was cause you did not call it in main

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

    How come you don’t pass by reference?

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

    04:14
    🤣😂

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

    4:05 :D It happens...

  • @кяѕниѕняи
    @кяѕниѕняи 6 วันที่ผ่านมา

    I am happy to see that i am not the only one who forget basic mathametics while i am wriing some code. 😁😁

    • @CodeBeauty
      @CodeBeauty  5 วันที่ผ่านมา

      oh it happens to me on daily basis :)

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

    Thank you

  • @maxscriptguru
    @maxscriptguru 22 วันที่ผ่านมา

    I saw friend classes used very badly in 3dsmax years ago. So I am not a fan of this C++ feature. C# got rid of the feature btw.

    • @CodeBeauty
      @CodeBeauty  11 วันที่ผ่านมา

      you like C#?
      check my Practical Programming Course at www.codebeautyacademy.com
      We are building real desktop application and you will be learning alongside other students, with me as your personal tutor. With this you will also gain access to exclusive Discord community.
      I'll be happy to have you there. :)

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

    🤣🤣🤣🤣🤣

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

    I love your contant and your stille in explain

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

    The reason the PrintResults function won't work is because you made it a member of the Homework class. So to access it you would have to use to dot operator after making an object of the homework class.

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

    Wow so nice I completed Your OOP C++ video and I was about to learn friend function and your uploading a video so nice thank you Ma'am

  • @a.yildiz6866
    @a.yildiz6866 ปีที่แล้ว

    Could you please make a video about when we should use "const", and when should we pass by const reference or by value.. Thank you!

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

    thank you so much, I watched 1000+ videos and they never explain everything in so much detail!!!

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

    The results from a calculator and this program for the area is different. Quite similar, yet big gap. Why is that? How is float rounding?

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

    What is the advantage of friend function over friend classes ???

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

    Mam, I want to develop an application for laptop functionality testing. I am new to c++, which tool I can use

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

    excelent . thanks . i download all your videos. thanks

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

    Can we access a friend function, friend member function and friend class in a same program?