These tutorial videos are very good. One question here: How do friend functions deal with templated classes, is there anything that needs to be done? For example, let's say the double_x(MyClass &object) multiplies x * 2.0 but x is a template variable and could be an int. How do you set double_x() to handle that case?
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.
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. :-)
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!
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)
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.
I just want to say that you are one of the best to simplify the subject and explain it keep going man ,thanks
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! :-)
you are the greatest teacher ,thanks buddy
You’re welcome, I’m glad you enjoyed it! :-)
These tutorial videos are very good. One question here: How do friend functions deal with templated classes, is there anything that needs to be done? For example, let's say the double_x(MyClass &object) multiplies x * 2.0 but x is a template variable and could be an int. How do you set double_x() to handle that case?
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.
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. :-)
WIll you cover SFML or some GUI with C++ ofc?
I hope to cover GUIs “one day” but I’m not sure when it will be. :-)
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!
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)
which environment setup you are using
good video Kevin!
Thanks Victor! :-)
What is the difference between assigning an array like " int arr[n] = {0}; " and using a loop or function?
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.
Good job
Thank you Faruq! :-)
Thanks :)
Thank you!