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

  Рет қаралды 110,699

CodeBeauty

CodeBeauty

Күн бұрын

📚 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.
Download Visual Assist here: bit.ly/WT-CB
I use it to enhance the performance, features, and support for C, C#, and C++ development in Visual Studio.
Download Ultra Edit here: bit.ly/UE-CB
It is a powerful, secure text editor designed specifically for programmers.
In programming, like in real life, exists the concept of friendship. In the same way that your friends in real life can access private areas of your life (that are inaccessible to other people), in programming, a friend function or a friend class can access private and protected members of a specific class.
In this video, you'll learn how to work with friend functions and classes, friend functions and classes common uses, as well as the most important tips related to friend functions and friend classes.
And at the end, you can find a homework task in order to practice programming on your own.
The solution for that task will be pinned in the comment.
☕ If you've found my content helpful and would like to support me, you now have the option to buy me a coffee or a cookie! It's a small gesture of gratitude that means a lot to me and helps me keep creating free educational videos for you. You can use the link below to make a contribution: bit.ly/CodeBeauty_BuyMeACoffee
However, please don't feel obligated to do so. I appreciate every one of you, and I will continue to share valuable content with you regardless of whether you choose to support me in this way. Thank you for being part of the Code Beauty community! ❤️😇
Contents:
00:00 - What are friend functions
00:52 - Best extension for Visual Studio C++
02:10 - Let's create a problem
07:19 - Solving the problem with friend functions
10:37 - Multiple friend functions
11:28 - Friend classes
14:48 - Important tips about friend functions and classes
16:22 - Homework (operator overloading and friend functions)
Videos mentioned in this tutorial that you should watch:
Must know Visual Assist features - • My top 5 Visual Assist...
Encapsulation - • C++ OOP - What is enca...
Inheritance - • C++ OOP - What is inhe...
Operator overloading - • C++ Operator Overloadi...
Add me on:
Instagram 📸 - / truecodebeauty
Twitter 🐦- / truecodebeauty

Пікірлер: 145
@CodeBeauty
@CodeBeauty 2 жыл бұрын
📚 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 KZfaqChannel { string Name; int SubscribersCount; public: KZfaqChannel(string name, int subscribersCount) { Name = name; SubscribersCount = subscribersCount; } bool operator==(const KZfaqChannel& 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 жыл бұрын
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!!!! 😀
@pavankumarnitta0329
@pavankumarnitta0329 2 жыл бұрын
Can you please post a full detailed long video on below two topics: Data structures using C++ STL using C++
@jaja7830
@jaja7830 11 ай бұрын
Imas svoj stil, objasnjavas jasno i detaljno. Puno truda ulazes u svaki video i to se vidi. Hvala jos jednom. :)
@retr0918
@retr0918 2 жыл бұрын
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.
@talm5568
@talm5568 Жыл бұрын
Finally found the ultimate teacher... So concrete and so useful. You're the best...
@muha0644
@muha0644 2 жыл бұрын
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!
@aritramajumder4982
@aritramajumder4982 Жыл бұрын
Hey Saldina, your lessons are greatt 😁. And one thing, I guess it's called perimeter, circumference is perimeter of circle...
@fernandomendes4026
@fernandomendes4026 2 жыл бұрын
at 4:16 she used a brazilian meme... I like this !!!
@joonbeomkim9898
@joonbeomkim9898 6 ай бұрын
I have watched three different videos of friend functions on KZfaq 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++.
@altoclef4989
@altoclef4989 2 жыл бұрын
Awesome stuff, thank you for helping me brush up on my OOP skills.
@tentandoumcover
@tentandoumcover Жыл бұрын
I'm in love with this channel, and even if I'm not fluent in english I can understand you pretty clearly.
@kolbe6436
@kolbe6436 2 жыл бұрын
Great Job! I learnt alot today, and I am grateful.🙂
@codeforlifehere
@codeforlifehere Жыл бұрын
One of the most clear explaination of Friend function on the internet.
@roshanpoudel5140
@roshanpoudel5140 2 жыл бұрын
Hey, waiting for the premiere ,lots of appreciation and thanks for teaching us.
@isaacl.quelemine8775
@isaacl.quelemine8775 2 жыл бұрын
I ready do admire your teaching always You’re quite amazing 😻 .
@rajnishsingh1348
@rajnishsingh1348 2 жыл бұрын
mam its my first time to watch your video . your explanation is great, thank you for this type of useful videos love from INDIA
@bestpractices2412
@bestpractices2412 2 жыл бұрын
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.
@brandonpanuco8546
@brandonpanuco8546 Жыл бұрын
Thank You! You explained it way better than how my book tried to! 👍👍👍
@sourabhsingh192
@sourabhsingh192 4 ай бұрын
she cleared the concept very clearly, good work
@eric-jt
@eric-jt 2 жыл бұрын
I come to your channel everyday to learn something new. Thanks!
@CodeBeauty
@CodeBeauty 2 жыл бұрын
I'm happy to hear that, cheers 🥰🥰
@quasirdp
@quasirdp 2 жыл бұрын
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
@houssemeddine5685
@houssemeddine5685 2 жыл бұрын
You are the best teacher ever. Thanks for reminding me how beautiful programming is. *_*
@Sooshee_J
@Sooshee_J 2 жыл бұрын
I finally understand them...thanks!
@ferfykins
@ferfykins 6 ай бұрын
Excellent explanation, ty so much!
@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
@jasnarmstrng
@jasnarmstrng Жыл бұрын
Wholesome programming content indeed 😊
@jakubsz4602
@jakubsz4602 2 жыл бұрын
incredible work!
@speedbird7587
@speedbird7587 Жыл бұрын
Really very instructive lecture ! Thank you
@nikhielsingh748
@nikhielsingh748 2 жыл бұрын
great video , love from South Africa
@abubakarusman5298
@abubakarusman5298 Жыл бұрын
Thanks alot for these kinda outstanding videos, it means alot to me (student)
@sangeeth.47
@sangeeth.47 6 ай бұрын
❤ Really Appreciate the efforts... Explained a lot of better than teaching in my university.
@krishsharma6276
@krishsharma6276 2 жыл бұрын
you are just awesome😇 I love the way you teach😄👌
@nastaranhendijani681
@nastaranhendijani681 4 ай бұрын
thank you, very helpful!
@sulfur32066
@sulfur32066 2 жыл бұрын
Good job, thanks 👍
@franktan9937
@franktan9937 4 ай бұрын
your lessons are great
@danielkolev7458
@danielkolev7458 Жыл бұрын
You need to use this pointer when setting the length in setA function . It is a good practice!
@robertingersoll3039
@robertingersoll3039 Жыл бұрын
excellent video, the humour was also good.
@xinking2644
@xinking2644 2 жыл бұрын
awesome! thanks for share!
@edclam
@edclam Жыл бұрын
I choose to stay not only because you're amusing (haha) also because you explain the concepts very well, step by step and logically.
@mohamedchraga5512
@mohamedchraga5512 2 жыл бұрын
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 ☺️
@gelongmundomo
@gelongmundomo 2 жыл бұрын
Hello from Philippines!
@mariacunha8508
@mariacunha8508 2 ай бұрын
Wow, I love how you can make a topic seem so simple and easy to understand!!! Love it!
@CodeBeauty
@CodeBeauty 2 ай бұрын
🥰🥰
@carloslugo4600
@carloslugo4600 2 жыл бұрын
Merry chrismas and happy new year.
@samanehimani7908
@samanehimani7908 Жыл бұрын
excelent . thanks . i download all your videos. thanks
@sravankumpati6564
@sravankumpati6564 7 ай бұрын
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.
@Ayush-qn7hy
@Ayush-qn7hy 2 жыл бұрын
Saldina how about a code review series? We would love to send you our C++ projects 🙂 and would love your reaction on it.
@bubble_gum_witch
@bubble_gum_witch 2 ай бұрын
thanks so much❤
@vihangajuly6316
@vihangajuly6316 2 жыл бұрын
best teacher😻🙂
@mustafaaltay4920
@mustafaaltay4920 Жыл бұрын
Amazing ve beneficial videos, thanks ...
@theflamingstar5140
@theflamingstar5140 2 жыл бұрын
I love your contant and your stille in explain
@reginaphalange1361
@reginaphalange1361 Жыл бұрын
Thank you
@Kometha
@Kometha 2 жыл бұрын
THANKS!!!
@vinicius.schmidt
@vinicius.schmidt 2 жыл бұрын
great content!
@harishraam6674
@harishraam6674 Жыл бұрын
Thankyou saldina.
@iamasra4122
@iamasra4122 2 жыл бұрын
You’re amazing 🤩🤩🤩🤩🤩
@immipixediter210
@immipixediter210 2 жыл бұрын
thanks
@razaalikhancyber
@razaalikhancyber 2 жыл бұрын
you are the best
@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.
@a.yildiz6866
@a.yildiz6866 11 ай бұрын
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!
@mazenas3443
@mazenas3443 2 жыл бұрын
thank u very much princess
@kavyag6326
@kavyag6326 Жыл бұрын
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?
@danielkolev7458
@danielkolev7458 Жыл бұрын
Nice work
@lilgohan
@lilgohan 7 ай бұрын
thank you for updating to dark mode
@razaalikhancyber
@razaalikhancyber 2 жыл бұрын
really nice
@Loki-vy5vg
@Loki-vy5vg 11 ай бұрын
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.
@aliali-xx8ur
@aliali-xx8ur 3 ай бұрын
THANKS
@CodeBeauty
@CodeBeauty 3 ай бұрын
You're welcome 🥰
@ukaszpaka1479
@ukaszpaka1479 Жыл бұрын
Hey! Is it a good idea to pass a parameter to the friend function by the constant reference?
@chrisv1459
@chrisv1459 11 ай бұрын
Instead of circumference it's called perimeter! Great videos thanks 👍
@akanguven114
@akanguven114 Жыл бұрын
we have not called PrintResults function yet, and walso we have to pass the et object as the parameter... God bless you!
@ashutoshsharma1994
@ashutoshsharma1994 2 жыл бұрын
what keyboard you are using, sounds fantastic
@ahmadahmad-ug8ls
@ahmadahmad-ug8ls 3 ай бұрын
u are a legend istg
@Anclavijo85
@Anclavijo85 Ай бұрын
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?
@truecodeface
@truecodeface 2 жыл бұрын
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.
@kubolor1234
@kubolor1234 19 күн бұрын
Suspenseful stuff...absolutely blindsided by the area of triangle formula 🤣
@user-zo7mx6cm5t
@user-zo7mx6cm5t 2 жыл бұрын
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?
@Kraboobee
@Kraboobee 8 ай бұрын
I actually did stay because you are extremely amusing 😂
@victordedon3917
@victordedon3917 2 жыл бұрын
Thou shall not fall in love with your teacher 😭😭😭😭
@The_double_side
@The_double_side 2 жыл бұрын
something similar ....... coincidence do happen wow.......
@RejhanTrubljanin
@RejhanTrubljanin Жыл бұрын
disgusting
@dxshawn532
@dxshawn532 9 ай бұрын
Victor are you saying you're gay?
@user-vz3cr8vu1n
@user-vz3cr8vu1n 6 ай бұрын
Simp init
@zero-ui1ew
@zero-ui1ew Ай бұрын
Nah u down bad
@arshmaanali714
@arshmaanali714 2 жыл бұрын
mam plzzzzzzzzzzzz 🙏🏽🙏🏽🙏🏽🙏🏽🙏🏽🙏🏽🙏🏽 make video on aggregation and composition in C++
@Morderkainer
@Morderkainer 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. 😔
@ashishjangra7167
@ashishjangra7167 2 жыл бұрын
Great mam. Where are you from
@arazmuhammetatayev7420
@arazmuhammetatayev7420 2 жыл бұрын
4:10 I watched that part like 5 times... so cute haha
@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.
@jamesmoran817
@jamesmoran817 9 ай бұрын
Would it be possible to post .txt with your KZfaq videos, it would be easier to follow along?
@anupnadagouda8240
@anupnadagouda8240 2 жыл бұрын
Mam, I want to develop an application for laptop functionality testing. I am new to c++, which tool I can use
@Timekepper
@Timekepper Жыл бұрын
What is the advantage of friend function over friend classes ???
@cybafour9124
@cybafour9124 2 жыл бұрын
What's theme you use
@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?
@guimoncao
@guimoncao 2 жыл бұрын
04:15 Fun fact, this meme isn't Julia Roberts
@chhamza4566
@chhamza4566 Жыл бұрын
Can we access a friend function, friend member function and friend class in a same program?
@d_113d
@d_113d 2 жыл бұрын
❤️❤️❤️
@SalmonSushi47
@SalmonSushi47 Ай бұрын
3:00 perimeter not circumference
@shibashabatnotski5163
@shibashabatnotski5163 2 жыл бұрын
damn, I had a question about this topic yesterday and I didn't know the answer :(
@TrailVapor
@TrailVapor 27 күн бұрын
a problem with using friend functions is that they are not as optimizable or as self documenting as comprehensive getters & setters.
@blendwolfe8291
@blendwolfe8291 2 жыл бұрын
Like #700! Great video 👌
@brainybits472
@brainybits472 Жыл бұрын
👏👏👏👏👏
@DgeisonAlexander
@DgeisonAlexander Жыл бұрын
Haha, 04:16 Brazilian meme --> Renata Sorrah brazilian actress!
@che5738
@che5738 Жыл бұрын
// 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
@RPBCACUEAIIBH
@RPBCACUEAIIBH 2 жыл бұрын
4:05 :D It happens...
@ZiaurRehman-ex3of
@ZiaurRehman-ex3of 2 ай бұрын
now printresult is not a global function that's why it give error
KINDNESS ALWAYS COME BACK
00:59
dednahype
Рет қаралды 137 МЛН
3M❤️ #thankyou #shorts
00:16
ウエスP -Mr Uekusa- Wes-P
Рет қаралды 14 МЛН
Final muy increíble 😱
00:46
Juan De Dios Pantoja 2
Рет қаралды 54 МЛН
What are header files in C++ ( PROGRAMMING TUTORIAL for beginners)
23:54
Why You Shouldn't Nest Your Code
8:30
CodeAesthetic
Рет қаралды 2,6 МЛН
Friend Functions | C++ Tutorial
13:05
Portfolio Courses
Рет қаралды 8 М.
C++ OOP - What is polymorphism in programming? (simple example)
15:20
why do header files even exist?
10:53
Low Level Learning
Рет қаралды 375 М.
are "smart pointers" actually smart?
9:44
Low Level Learning
Рет қаралды 71 М.
Object Oriented Programming (OOP) in C++ Course
1:30:26
freeCodeCamp.org
Рет қаралды 2,4 МЛН
5 Good Python Habits
17:35
Indently
Рет қаралды 421 М.
SMART POINTERS in C++ (for beginners in 20 minutes)
24:32
CodeBeauty
Рет қаралды 95 М.
Easy Art with AR Drawing App - Step by step for Beginners
0:27
Melli Art School
Рет қаралды 10 МЛН
OZON РАЗБИЛИ 3 КОМПЬЮТЕРА
0:57
Кинг Комп Shorts
Рет қаралды 1,5 МЛН
WATERPROOF RATED IP-69🌧️#oppo #oppof27pro#oppoindia
0:10
Fivestar Mobile
Рет қаралды 17 МЛН