Friend Functions | C++ Tutorial

  Рет қаралды 8,679

Portfolio Courses

Portfolio Courses

2 жыл бұрын

An explanation of what friend functions are and examples of how to use them in C++. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

Пікірлер: 18
@yahyaamjad7183
@yahyaamjad7183 Жыл бұрын
I just want to say that you are one of the best to simplify the subject and explain it keep going man ,thanks
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome Yahya and thank you so much for the kind feedback, I'm so glad to hear the videos are helping to simplify the subjects for you! :-)
@Victor-fl8ex
@Victor-fl8ex 2 жыл бұрын
good video Kevin!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thanks Victor! :-)
@aryanviolett4606
@aryanviolett4606 6 ай бұрын
Thanks :)
@faruqnad4758
@faruqnad4758 Жыл бұрын
Good job
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you Faruq! :-)
@sadaqatali-y4n
@sadaqatali-y4n 8 ай бұрын
which environment setup you are using
@ValliNayagamChokkalingam
@ValliNayagamChokkalingam Жыл бұрын
Hi! How do you decide between using a reference to an object instance vs an object instance directly as a parameter for a function? Thank you! Have a good one!
@phoe87
@phoe87 5 ай бұрын
I know it's 10 months late but in case you haven't figured it out already, passing an instance of a class as a parameter copies it, you either have to pass it by reference when it's instantiated on the stack, or by pointer when it's instantiated on the heap (a pointer to the stack works too)
@gedariaofficial8818
@gedariaofficial8818 Жыл бұрын
Isn't friend function violation of Opened/Closed principle? When you change your private members, it will break the friend functions that are declared somewhere else in the program. Also isn't it violation of encapsulation as well? Why bother with private specifier if you can write function that can freely access private members? Are friend functions considered a good practice? I am fairly new, please correct me if I am wrong.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
These are really excellent 'deep' questions. :-) I would say that there is room for opinion though in the answers in that the answers are more complicated than 'yes' or 'no'. My opinion... very strictly speaking, friend functions can violate encapsulation, but in some sense all public member functions can violate encapsulation as well (they can also access private members, and break the motivation/point of encapsulation in the process). Like public member functions, friend functions are a good practice when used appropriately. You'll find lots of opinions/prescriptions on this sort of thing online: www.google.com/search?&q=do+friend+function+violates+encapsulation. I don't really take very strong positions on topics like this myself because I'm more of a pragmatic "if it's better than the alternatives, then use it" sort of developer. :-)
@rangutango
@rangutango 8 ай бұрын
SO when would I use a friend function? Couldn't I just use a get function?
@jaceallen7400
@jaceallen7400 4 ай бұрын
That's exactly what I was hoping to find out by watching this video...but alas...
@Victor-fl8ex
@Victor-fl8ex 2 жыл бұрын
WIll you cover SFML or some GUI with C++ ofc?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
I hope to cover GUIs “one day” but I’m not sure when it will be. :-)
@shafayet0198
@shafayet0198 Жыл бұрын
What is the difference between assigning an array like " int arr[n] = {0}; " and using a loop or function?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
We can expect int arr[n[] = {0}; to be more efficient compared to using a loop or function. In that case the compiler "knows everything it needs to know" to initialize the array when compiling the program. Whereas with a loop or function we'll be "executing code at runtime" to initialize the array, potentially with different values each time. We an expect using a loop or a function to create more work to be done at runtime as the program is executing.
Operator Overloading Using Friend Functions | C++ Tutorial
15:04
Portfolio Courses
Рет қаралды 8 М.
new & delete Operators For Dynamic Memory Allocation | C++ Tutorial
15:52
Portfolio Courses
Рет қаралды 27 М.
Mom's Unique Approach to Teaching Kids Hygiene #shorts
00:16
Fabiosa Stories
Рет қаралды 36 МЛН
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 53 МЛН
Red❤️+Green💚=
00:38
ISSEI / いっせい
Рет қаралды 88 МЛН
MISS CIRCLE STUDENTS BULLY ME!
00:12
Andreas Eskander
Рет қаралды 20 МЛН
Friend functions and classes in C++ (Programming for beginners)
18:18
Member Initializer Lists | C++ Tutorial
23:10
Portfolio Courses
Рет қаралды 8 М.
Multiple Inheritance Deep Dive | C++ Tutorial
14:53
Portfolio Courses
Рет қаралды 9 М.
Static Member Functions | C++ Tutorial
8:19
Portfolio Courses
Рет қаралды 9 М.
Function Templates | C++ Tutorial
10:54
Portfolio Courses
Рет қаралды 7 М.
Dynamic Binding (Polymorphism) With The Virtual Keyword | C++ Tutorial
9:57
OPERATORS and OPERATOR OVERLOADING in C++
12:44
The Cherno
Рет қаралды 367 М.
Operator Overloading Introduction | C++ Tutorial
8:01
Portfolio Courses
Рет қаралды 11 М.
Mom's Unique Approach to Teaching Kids Hygiene #shorts
00:16
Fabiosa Stories
Рет қаралды 36 МЛН