Friend Functions | C++ Tutorial

Поділитися
Вставка
  • Опубліковано 31 січ 2025

КОМЕНТАРІ • 20

  • @yahyaamjad7183
    @yahyaamjad7183 Рік тому +5

    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  Рік тому +1

      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! :-)

  • @ahmadjawmar2242
    @ahmadjawmar2242 5 місяців тому

    you are the greatest teacher ,thanks buddy

    • @PortfolioCourses
      @PortfolioCourses  5 місяців тому

      You’re welcome, I’m glad you enjoyed it! :-)

  • @artemiasalina1860
    @artemiasalina1860 5 місяців тому

    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?

  • @gedariaofficial8818
    @gedariaofficial8818 Рік тому +1

    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  Рік тому +3

      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. :-)

  • @ValliNayagamChokkalingam
    @ValliNayagamChokkalingam Рік тому +1

    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 11 місяців тому +1

      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)

  • @Vichained
    @Vichained 2 роки тому +1

    good video Kevin!

  • @Vichained
    @Vichained 2 роки тому +1

    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 2 роки тому

    What is the difference between assigning an array like " int arr[n] = {0}; " and using a loop or function?

    • @PortfolioCourses
      @PortfolioCourses  2 роки тому

      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.

  • @sadaqatali-y4n
    @sadaqatali-y4n Рік тому

    which environment setup you are using

  • @faruqnad4758
    @faruqnad4758 2 роки тому

    Good job

  • @aryanviolett4606
    @aryanviolett4606 Рік тому

    Thanks :)

  • @WhereToClick
    @WhereToClick 5 місяців тому

    Thank you!