this Keyword And Use Cases Explained | C++ Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 พ.ย. 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! :-)

  • @weemanling
    @weemanling 8 หลายเดือนก่อน

    Thank you. Finally it makes sense to me.

    • @PortfolioCourses
      @PortfolioCourses  8 หลายเดือนก่อน

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

  • @ARANDOMOPENAIUSER
    @ARANDOMOPENAIUSER ปีที่แล้ว

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

  • @MF18-2020
    @MF18-2020 3 หลายเดือนก่อน +1

    thank you man

  • @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: th-cam.com/video/e3DN1RaYVYQ/w-d-xo.html. And this video covers pass by reference: th-cam.com/video/cxysUPZH65Y/w-d-xo.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! :-)

  • @valentincafferata182
    @valentincafferata182 4 หลายเดือนก่อน

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

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

  • @hamudxd9497
    @hamudxd9497 8 หลายเดือนก่อน

    Top class❤❤❤

  • @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!

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

  • @niranjand8595
    @niranjand8595 ปีที่แล้ว

    Which IDE is this