this Keyword And Use Cases Explained | C++ Tutorial

  Рет қаралды 5,413

Portfolio Courses

Portfolio Courses

2 жыл бұрын

How to use the this keyword in C++ including several use cases. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!

Пікірлер: 32
@M3t4lik
@M3t4lik Жыл бұрын
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 жыл бұрын
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!
@weemanling
@weemanling 4 ай бұрын
Thank you. Finally it makes sense to me.
@PortfolioCourses
@PortfolioCourses 4 ай бұрын
You're welcome, I'm glad it helped you out! :-)
@valentincafferata182
@valentincafferata182 2 күн бұрын
i finally get itttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt, thank you!!!!!
@hamudxd9497
@hamudxd9497 3 ай бұрын
Top class❤❤❤
@moyo8960
@moyo8960 Жыл бұрын
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 Жыл бұрын
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 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 Жыл бұрын
So & does not mean the same thing in C when we are working with references. This video covers reference variables: kzfaq.info/get/bejne/m5l0gZSDxr-6iYU.html. And this video covers pass by reference: kzfaq.info/get/bejne/md6ppriBv66aZY0.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! :-)
@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 Жыл бұрын
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! :-)
@Victor-fl8ex
@Victor-fl8ex 2 жыл бұрын
good video mate. Keep it up
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you Victor, I'm glad to hear you enjoyed the video! :-D
@Victor-fl8ex
@Victor-fl8ex 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 жыл бұрын
@@Victor-fl8ex 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.
@Victor-fl8ex
@Victor-fl8ex 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 жыл бұрын
@@Victor-fl8ex 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 Жыл бұрын
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! :-)
@user-yk2dc6yr7q
@user-yk2dc6yr7q 7 ай бұрын
my timestamp: 5:07 passing the 'this' / object-pointer as an arguement to a function
@niranjand8595
@niranjand8595 Жыл бұрын
Which IDE is this
@PortfolioCourses
@PortfolioCourses Жыл бұрын
This is Xcode on MacOS. :-)
Reference Variables | C++ Tutorial
12:04
Portfolio Courses
Рет қаралды 3,6 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 285 М.
NERF WAR HEAVY: Drone Battle!
00:30
MacDannyGun
Рет қаралды 46 МЛН
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 4 МЛН
Member Initializer Lists | C++ Tutorial
23:10
Portfolio Courses
Рет қаралды 8 М.
new & delete Operators For Dynamic Memory Allocation | C++ Tutorial
15:52
Portfolio Courses
Рет қаралды 26 М.
Dynamic Binding (Polymorphism) With The Virtual Keyword | C++ Tutorial
9:57
are "smart pointers" actually smart?
9:44
Low Level Learning
Рет қаралды 71 М.
The "this" keyword in C++
6:08
The Cherno
Рет қаралды 247 М.
Pass By Reference | C++ Tutorial
10:21
Portfolio Courses
Рет қаралды 9 М.
you will never ask about pointers again after watching this video
8:03
Low Level Learning
Рет қаралды 2,1 МЛН
This Pointer In C++
12:22
CppNuts
Рет қаралды 32 М.
Exception Handling | C++ Tutorial
14:49
Portfolio Courses
Рет қаралды 15 М.