this Keyword And Use Cases Explained | C++ Tutorial

Поділитися
Вставка
  • Опубліковано 15 гру 2024

КОМЕНТАРІ • 34

  • @M3t4lik
    @M3t4lik Рік тому +6

    This is the clearest explanation of how the 'this' pointer works and is used. Thank you.

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

      You’re welcome, I’m glad that you found the explanation clear! :-)

  • @yuwownly8630
    @yuwownly8630 2 роки тому +4

    Dude. Thanks for this video, it really helps a lot!!! I'm looking forward to more tutorials.

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

      You're welcome! 🙂 I'm glad to hear that it helped you!

  • @moyo8960
    @moyo8960 2 роки тому +3

    The this-keyword was not necessary in the increase_age() and increase_and_output_age() methods, correct? I tested the code without it and it worked. So did you just use them for the sake of argument and to demonstrate or is it good practice to include it in such places? I was especially confused by you saying that the keyword enables the object to access its own member variables in its own member functions which is true even without 'this' being used. I would be grateful if you cleared this up, thanks!
    As this is the first question one of your videos left me with, I also want to use this opportunity to thank you for your content. I've only just gotten into OOP and so far tried to make my way through with stackoverflow. With your videos I'm getting a great overview and solid base to build more knowledge on later, so thank you very much for all the time and effort you put in these videos. Very concise! And I love how you slowly build your examples, structuring it in a way that you can use previous examples seamlessly to demonstrate new points!

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

      It's true, you don't *need* to use the this keyword to access member variables, that is just one of the things that it allows you to do. :-)
      And thank you so much for the kind and positive feedback, I really appreciate you taking the time to let me know these videos are helping you and that you enjoy the structure and format. It means a whole lot to me that these videos are helpful to people! :-)

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

    Thanks!

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

      Woah, thank you so much Valli-Nayagam!!!! :-)

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

      @@PortfolioCourses Thanks for the amazing tutorials! It's a really small amount but I would love to contribute more soon (still in college)!

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

      Good luck with your courses! :-)

  • @weemanling
    @weemanling 9 місяців тому

    Thank you. Finally it makes sense to me.

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

      You're welcome, I'm glad it helped you out! :-)

  • @MF18-2020
    @MF18-2020 4 місяці тому +1

    thank you man

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

    my timestamp: 5:07 passing the 'this' / object-pointer as an arguement to a function

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

    Now I have a better understanding of "this". I read in a C++ book that when the creator of a class define a member as private to "protect" it from the consumer of the object, it is just a logical protection which is very easy to circumvent. So, I guess one way to circumvent this logical protection is to get the pointer of the object, then increase the pointer and read the value stored in that address. Is this correct? Thank you very much for this video.

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

      Great question Eduardo! :-) I think by "circumvent" they might mean that a programmer simply has to change "private" to "public" and then they have access to the member. So if a programmer wants access to something they shouldn't, really the keyword private is more of a signal to the programmer that the class was designed with the intention to keep the member private, but ultimately "private" doesn't stop the programmer from doing whatever they want.

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

      @@PortfolioCourses Thank you for your answer. I was thinking it is a way how a hacker can get access to a private member.

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

      You're welcome! :-)

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

    i finally get itttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt, thank you!!!!!

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

    good video mate. Keep it up

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

      Thank you Victor, I'm glad to hear you enjoyed the video! :-D

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

      @@PortfolioCourses Could you do a video of a currencies exchange proyect using OOP? I did one with 4 currencies: USD, EUR, GBP and CHF but Im sure it can be improved by a lot, so i wanna see how would you do it. Besides that, it would an awesome tutorial to learn new stuff

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

      @@Vichained I could possibly do that, but what would the requirements be for the currency exchange in terms of feature and functionalities? i.e. what does it need to do.

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

      @@PortfolioCourses ask user balance. What currency he has. Into which one he wants to convert it and then the result after the conversion. You could also add the feature where the user just converts a part of his overall balance, not all of it.

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

      @@Vichained Interesting, there is a number of ways to go about it. Doing it an "OO way" almost makes me wonder if the idea is to use polymorphism and inheritance with a base class and derived classes for each currency. I've added this to my list of ideas, thank you, hopefully one day I can make a video on this.

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

    thanks once again! I am a bit confused with the difference between references and pointers - I am clear with pointers, dereferencing etc., in C. Getting confused with references in C++ (does & something refer the address in C++ like in C?).

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

      So & does not mean the same thing in C when we are working with references. This video covers reference variables: ua-cam.com/video/e3DN1RaYVYQ/v-deo.html. And this video covers pass by reference: ua-cam.com/video/cxysUPZH65Y/v-deo.html. Maybe those can help to explain things better? But references and pointers are two different concepts, a reference "is" what it references (there is no difference between it and what it references), where as a pointer is a variable that stores a memory address of another variable (and we say it 'points' to that variable).

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

      @@PortfolioCourses Thanks!

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

      You're welcome! :-)

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

    Which IDE is this

  • @hamudxd9497
    @hamudxd9497 9 місяців тому

    Top class❤❤❤