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 Жыл бұрын
I just want to say that you are one of the best to simplify the subject and explain it keep going man ,thanks
@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-fl8ex2 жыл бұрын
good video Kevin!
@PortfolioCourses2 жыл бұрын
Thanks Victor! :-)
@aryanviolett46066 ай бұрын
Thanks :)
@faruqnad4758 Жыл бұрын
Good job
@PortfolioCourses Жыл бұрын
Thank you Faruq! :-)
@sadaqatali-y4n8 ай бұрын
which environment setup you are using
@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!
@phoe875 ай бұрын
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 Жыл бұрын
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 Жыл бұрын
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. :-)
@rangutango8 ай бұрын
SO when would I use a friend function? Couldn't I just use a get function?
@jaceallen74004 ай бұрын
That's exactly what I was hoping to find out by watching this video...but alas...
@Victor-fl8ex2 жыл бұрын
WIll you cover SFML or some GUI with C++ ofc?
@PortfolioCourses2 жыл бұрын
I hope to cover GUIs “one day” but I’m not sure when it will be. :-)
@shafayet0198 Жыл бұрын
What is the difference between assigning an array like " int arr[n] = {0}; " and using a loop or function?
@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.