Тёмный

Function Pointers in C++ 

The Cherno
Подписаться 661 тыс.
Просмотров 390 тыс.
50% 1

Опубликовано:

 

26 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 365   
@jun7452
@jun7452 6 месяцев назад
Man, that is absolutely crazy! Honestly, the more i learn about C++ the more i want to learn about the language, it's like you're fighting a Hydra, you cut one head but two grow as a replacement. I know these things aren't actually easy to get, and since there are like an infinite ammount of things you can do with this language, sometimes it just makes the programmer's life harder. But i think that this just shows that C++ is all about giving control to the programmer to do basically anything he wants to do, which i find it to be fascinating in it's own way. I'm aware that you won't read this comment since this video has been out for a long time, but i seriously am grateful you made this huge ass playlist bro! It's really really helping me to learn this language Thanks bro!
@EmbeddedSorcery
@EmbeddedSorcery 5 лет назад
Pointer concept isn't hard. Syntax is just awkward and confusing imo.
@SankoshSaha_01
@SankoshSaha_01 4 года назад
honestly that the problem; i forget it everytime!
@joestevenson5568
@joestevenson5568 4 года назад
You have to read the syntax backwards
@Mateus.007
@Mateus.007 4 года назад
int (*f(float (*)(long), char *))(double);
@Simon-jw1ww
@Simon-jw1ww 3 года назад
if you mess it up it can be very dangerous too. One of the Syntaxes you have to understand before you try around. Thanks god c++ has smartpointers aswell.
@obinator9065
@obinator9065 3 года назад
@@Simon-jw1ww function pointers have nothing to do with smart pointers. For something like this you should use lambdas and std::function.
@kinggore5229
@kinggore5229 4 года назад
Someone give this man a medal, pls.
@BlackJar72
@BlackJar72 6 лет назад
A+++++ content! I've been wanting to learn more about function pointers.
@louarn
@louarn 6 лет назад
It's C++, not A+++++.
@richardlighthouse5328
@richardlighthouse5328 6 лет назад
@Louarn he meant grade: A+++++
@louarn
@louarn 6 лет назад
@@richardlighthouse5328 It was a joke
@vertigo6982
@vertigo6982 6 лет назад
Now on to function objects, and functors!
@diamaudixaudioltd.299
@diamaudixaudioltd.299 2 года назад
needs more +'s
@PythonPlusPlus
@PythonPlusPlus 6 лет назад
Who else is binge watching the playlist?
@Caighy
@Caighy 5 лет назад
yup.
@smurf123444
@smurf123444 5 лет назад
me!
@abdulalhazred5924
@abdulalhazred5924 5 лет назад
only you, I'm just looking for some specific stuff
@edencheung8468
@edencheung8468 5 лет назад
Mememememe
@RamiAwar
@RamiAwar 4 года назад
> Netflix
@vipulkamani6538
@vipulkamani6538 4 года назад
By far the best videos on C++. Thanks man! You just taught me overnight what my professor couldn't in 7 weeks.
@neo-babylon7872
@neo-babylon7872 5 лет назад
Dude you're so good at explaining stuff. I was trying to understand function pointers for so long and all it took was this video. Also really good job on the threading video. Keep it up!
@shah.kairav
@shah.kairav 2 года назад
Another nice use-case of function pointers could be system calls in OS development. You can talk about how the operating system stores an array of function pointer corresponding to each system call and that helps calling functions simply by indexing in that array.
@NeoKailthas
@NeoKailthas 3 года назад
This is like when you are half way through the semester and half the class dropped out or changed major.
@some_one
@some_one 3 года назад
i just want to see how many are left in the end
@ryanbinter2447
@ryanbinter2447 6 лет назад
i love that you give a real useful example! ive seen bucky's videos and he never does this. he just tells you the idea and i guess assumes you know when to apply it. great job!
@reenamola2162
@reenamola2162 2 года назад
bucky's tutorials are way better. cherno overcomplicates things. there's nothing hes done here that cant be done with just normal functions so he hasn't demonstrated on why u NEED to use function pointers.
@TheCodeHunter
@TheCodeHunter 2 года назад
@@reenamola2162 cherno goes into proper detail, Bucky just scratches the surface
@tyreerobinson2016
@tyreerobinson2016 4 года назад
Your videos are absolutly amazing! You mix it up! Most youtubers just make you stare at a console through the whole course, and they only use their cursor to explain things. This playlist is well put together and well worth my time. Keep up the good work
@AswinJP
@AswinJP 4 года назад
Very few people do such an excellent job at this. Thank you Cherno! :)
@miles7267
@miles7267 4 года назад
I think what makes you so much better than everyone else is the fact that you give examples of where you would actually use all the things you teach in code.
@vvanchesa
@vvanchesa Год назад
Found your c++ series now. To learn C++ and dive in quickly your videos are absolute great!
@NeoKailthas
@NeoKailthas 3 года назад
"Gentle introduction" lol 😆
@ectoid6316
@ectoid6316 5 лет назад
I like your videos, sometimes I just need a quick look into a subject and don't have the time to read the technical reference pages. So I just crank your videos double speed and blast my brain. :D thnx
@DanielLiljeberg
@DanielLiljeberg Год назад
This brought back memories... I remember back in the early 2000 when I added a console to my game engine and hooked up function pointers to strings to be able to call those functions from the console :P
@eventhisidistaken
@eventhisidistaken 3 года назад
Function pointers were the precursors to OO. On rare occasion, I still use function pointers ( for dll support) , but really, you should avoid them when they are not necessary, not just because of the obtuse syntax, but because they are too loose - which means intractable bugs. I have seen people essentially reinvent c++ using #define and function pointers. I'm sure they thought it was really clever, but they were the only people willing to maintain the code. As soon as they leave the project, the first thing that happens is others toss their unmaintainable garbage code into the bit bucket and start over.
@josuevargas7252
@josuevargas7252 5 лет назад
Jesssss.......How incredible channel full of C++ special content.Thankyou very much.It's hard to find something like you here in my classroom....
@ETZERBEATS
@ETZERBEATS 3 года назад
Your videos are amaizing, I was struggling with pointers and function pointers on my faculty projects and your tutorials made my life easier. Thanks and keep doing the good work.
@SaifuddinEvloev
@SaifuddinEvloev Год назад
Function pointers allow us to use the concept of higher order function map, if the map function is too complex, then lambda functions won't be readable. So I think that function pointers are still an important part of C++.
@annahakobian7371
@annahakobian7371 5 лет назад
best c++ tutorials, thanks man
@yang-z
@yang-z 4 года назад
A function and a pointer to the function are different types. When assign a function to a variable, func converts itself to a pointer implicitly, just as you mentioned. On the other hand, we can use a ptr to a func to "interact" with "operator ()" just as func itself, just because the "()" is overloaded implicitly, I guess. Actually, a function is able to be "quoted" by reference with the original type rather than a pointer. But when you want to store several functions to a array to do a batch call, the pointers are stored.
@Hasansaid51
@Hasansaid51 4 года назад
That explanation at 1:04 just clicked in my head and I didn’t even watch the rest of the video. Thanks brotha 🙏🏾
@muhammadarslanrana942
@muhammadarslanrana942 4 года назад
with this we can implement map(), reduce(), filter() functions as well.
@hlrbBrambleX
@hlrbBrambleX 2 года назад
I just realized this is how callback function works. Amazing!
@zoronic6248
@zoronic6248 4 года назад
I know it's a bit late, but GODDAMN THAT HAIRCUT MAN!!!!! Everyone looks good with a fade and part
@GenericPhantom1
@GenericPhantom1 Год назад
The name says it all. It points towards a function instead of a variable.
@robfei-u6b
@robfei-u6b Год назад
this lesson which involves some many technical things such us auto, vector, typedef, function pointer, reference, even iterator inside
@iteratedofficial
@iteratedofficial 3 года назад
Probably the best c++ tutor on youtube
@Fol2ey
@Fol2ey 3 года назад
Dude. Your explanations are saving my life right now!
@duchaolv5876
@duchaolv5876 3 года назад
Every time I want to know something about modern c++, I come here. Good job Cherno!
@daveski084
@daveski084 5 лет назад
He's so cute, makes learning C++ that much better lol.
@Ebiko
@Ebiko 2 года назад
i personally love function pointers. I regulary store them in hashmaps , to call a similar, but different funktion every time. Like when i create elements of some sort, but the functions are only similiar in theory, but the execution is different, even if the result is the same. And at this point, i create a HashMap, calling the functions by keyword, with needed parameters. Thats so cool, it really helps me keep my functions organized, and i can add another element to the Map easily at any point For example when i want to parse Network data from another program, or via Rest APIs
@abhisheksa6635
@abhisheksa6635 Год назад
Man have been coding for a while, even that passing function inside another function using function pointer is sort of a overkill but yeah that's a way and can be used. I am majorly from a C background and mostly in my code we have seen the function pointer array but this was next level, the lambda is not known to me much, will go through and understand it.
@charr6108
@charr6108 2 года назад
OMG! did i just learnt lamda and function pointer in 10 minutes... awesome!
@sunilpatro1047
@sunilpatro1047 5 лет назад
Awesome explanation. I did search a lot but couldn't understand. But now all my doubts are clear after watching this video. Great content.
@PirKate
@PirKate 3 года назад
Great content! I was trying to write a homework and couldn't understand what I was doing wrong. after this video I could fix it immediately. VERY HELPFUL THANK YOU
@DiogoManteu
@DiogoManteu Год назад
Such a great explanation with examples.
@NeZversSounds
@NeZversSounds 4 года назад
I learned a similar thing in GameMaker and used for Finite State Machine, where state function is assigned to a variable that is called each game frame.
@jakobhuetter
@jakobhuetter 3 года назад
Love your videos! Helping me a lot with my university stuff!
@nandukrishna8142
@nandukrishna8142 2 года назад
That helped me so much in writing my own game engine with glut window and opengl
@hishamsomroz6913
@hishamsomroz6913 3 года назад
finally a channel whose videos i dont have to watch at 1.5x or 2x
@Simon-fu8sd
@Simon-fu8sd 2 года назад
I just find this so cool
@onyinyechichukwuma689
@onyinyechichukwuma689 2 года назад
The best C++ explanations EVER! Thanks!
@mms0537
@mms0537 4 года назад
I respect you dude
@AngelTaylorgang809
@AngelTaylorgang809 4 года назад
Start a data structure series please, greetings from Texas
@leducphuclong
@leducphuclong 5 месяцев назад
Thank you so much !! Great Teacher !!
@qy4247
@qy4247 3 года назад
Really good tutorial. Thx from China ❤
@nuriya9000
@nuriya9000 5 лет назад
Thank you so much!! I was revising cpp and I got stuck here. This really helped me a bunch. Definitely subscribing!
@AxElKo440
@AxElKo440 6 лет назад
Man, it's awesome, thank you so much for these lessons ♥
@haven4512
@haven4512 4 года назад
Thanks for making these videos, they really help a lot!
@figurehe4d
@figurehe4d 6 лет назад
excellent video. well explained. function pointers seem useful but the way I've been exposed to them so far only highlights the confusion!
@lemonextract1325
@lemonextract1325 10 месяцев назад
thank you
@jannesopanen8032
@jannesopanen8032 3 года назад
This is very handy matter in C++. I can pass a pointer as a parameter, pointer to function which I want to be in charge of handling values. :D
@JoCS11152
@JoCS11152 Год назад
mate i fucking love your series
@lucianbetke
@lucianbetke 3 года назад
Cool mister. A good explanation.
@masterproducts0
@masterproducts0 6 лет назад
The simple explaination makes it very helpful! :) Thank you for this series and keep going like you do.
@LAB_XI
@LAB_XI 8 месяцев назад
Great as usual 🔥
@JesseLeeHumphry
@JesseLeeHumphry 2 года назад
I've been working with UE4 and dispatchers seem to work based on function pointers, but I was never sure what a function pointer _was_ or how it was _written_ because UE code is so....'nebulous' isn't the right word, it's just kinda hard to track stuff down is all. And this video got me caught up. A+ stuff right here.
@momentswithjireh3921
@momentswithjireh3921 3 года назад
Thank you Cherno for this super fantastic explanation!
@danklabunde
@danklabunde 4 года назад
I have always struggled with pointers but this video actually turned on a lightbulb for me XD. I know function pointers are different but the "pointer theory" if you will makes much more sense now!
@ianpan0102
@ianpan0102 3 года назад
Brilliant content. I can't thank you enough, Cherno!
@joseponce6250
@joseponce6250 2 года назад
thank you!!
@gvcallen
@gvcallen 4 года назад
That last bit blew my mind haha. main() calls ForEach which then runs a for loop and "calls" the lambda function which then revisits the for loop can calls the lambda again etc. To make matters worse - ForEach could then still return a value. Lol. Thanks for making my brain hurt Cherno
@eventhisidistaken
@eventhisidistaken 3 года назад
If it hurts your brain to look at it, then it's usually bad code. I will say, brain hurt is not uncommon when dealing with templates, but it's a necessary pain.
@gvcallen
@gvcallen 3 года назад
@@eventhisidistaken his code was merely demonstrative. So doesnt really matter if it's "good" or "bad"
@eventhisidistaken
@eventhisidistaken 3 года назад
@@gvcallen It's demonstrative of what *not* to do.
@PflanzenChirurg
@PflanzenChirurg 6 лет назад
Im so in love with u that u continue this series
@naughtrussel5787
@naughtrussel5787 6 лет назад
Thank you for cool vids. Plz don't stop.
@MohdFaisal-ie6mo
@MohdFaisal-ie6mo 6 лет назад
Keep up the good work. RU-vid need experience coders like you.
@santhoshnagarajs3489
@santhoshnagarajs3489 6 лет назад
finally i understand why there is need for function pointers!! thank you .
@zyulaikhaerhad
@zyulaikhaerhad 3 года назад
Thank you!! You just saved me and my assignment from the due date
@avnishs.2514
@avnishs.2514 4 года назад
Amazing video! Helped me understand better
@foomoo1088
@foomoo1088 2 года назад
Would be nice to include example with a class member function as well! There’s a couple tricky details to attend to in that case (non static class member function)
@Raul-vg3wt
@Raul-vg3wt 2 года назад
Would you be able to explain the details?? I haven't had much luck looking an answer up. Running into issue with this exact problem.
@foomoo1088
@foomoo1088 2 года назад
@@Raul-vg3wt I’ll try to post an example this weekend (crunching this week)
@Raul-vg3wt
@Raul-vg3wt 2 года назад
I had a tough google session but I managed to figure out how it works. A video would be great tho. There needs to be more on the internet about this subject. 👍
@WhosTheBossHD
@WhosTheBossHD 5 лет назад
In C# i use Action for function pointers. Function pointers are great for Publish/Subscription type of projects.
@samuelmaucaille702
@samuelmaucaille702 5 лет назад
Bro you're a fantastic teacher! thanks a lot!
@frederickmloka5454
@frederickmloka5454 5 лет назад
Thanks for demystifying subject
@laurentiudobrescu9045
@laurentiudobrescu9045 6 лет назад
Good work ! I need this video , it's awesome !
@danielc4267
@danielc4267 6 лет назад
Great content. Thank you cherno
@Hemanth83439
@Hemanth83439 Год назад
pretty cool
@andreskoszutski4364
@andreskoszutski4364 3 года назад
.... in the future... Just kidding. I find your series extremely useful.
@Decco6306
@Decco6306 4 года назад
wow A Programmer with awesome video quality that doenst use a Mac I appreciate that
@zackjandali
@zackjandali 5 лет назад
@TheChernoProject I've never seen that kind of for loop! I kinda understand what it does: for (every index in : this array) do this; I'd like to see what other ways that could be used! Could you do a short video, or dedicate part of a video to explaining that. If you've already done that, can you show me where to look? :) Thanks for the vids, they're so helpful
@hankstalica1922
@hankstalica1922 4 года назад
Excellent vid.
@k-tech2937
@k-tech2937 3 года назад
Awesome content. Function pointer are awesome, however I struggle with passing member functions as pointers. So far i have been only able to pass static member functions, if i defiene non static function and try to pass it as a parameter into another function i end up wth this error: non-standard syntax; use '&' to create a pointer to member. Is there a way tou use non static member functions as pointer in c++?
@trongnhantran3358
@trongnhantran3358 Год назад
This blow my mind!!
@Idan-tc5rt
@Idan-tc5rt 6 лет назад
Cherno what are the odds that you'll make a video about Standard Template Library in this series ? I can't find any good guides for it.
@gabeitch7786
@gabeitch7786 6 лет назад
Idan try Derek banas series
@TheMR-777
@TheMR-777 4 года назад
@@gabeitch7786 O man! Don't know how to thank you! U just showed me quite an *AMAZING* Channel! Definitely gonna follow this! Many Thanks!
@gabeitch7786
@gabeitch7786 4 года назад
@@TheMR-777 No problem buddy
@MrMamanDon
@MrMamanDon 4 года назад
Learn from cppcon talks, and people like Jason turner. Cherno is great for revising basics.
@voiddeepstorage6533
@voiddeepstorage6533 3 года назад
you should do a video about using variadic templates function pointers, its a really cool topic.
@pmcgee003
@pmcgee003 2 года назад
Showing functional (trailing return) style might give another way to think of it : auto (*foo)( int ) -> void;
@lahusa_
@lahusa_ 6 лет назад
That Haircut though xD
@nguyenhoangminhtrung2779
@nguyenhoangminhtrung2779 4 года назад
It's like End Game hawkeye
@gunrunjk
@gunrunjk 6 лет назад
I always enjoy your video.
@jsnmad
@jsnmad 4 года назад
C++ Callbacks! Nice
@adocarpel7770
@adocarpel7770 6 лет назад
many thanks
@dpalmer4588
@dpalmer4588 5 лет назад
So, like nested functions, essentially? very cool
@shahadalrawi6744
@shahadalrawi6744 7 месяцев назад
The life savior
@tokita1230
@tokita1230 6 лет назад
I hope that you'll talk about method pointers in the next video and how you can use them without the standard library.
@iparken
@iparken 4 года назад
12:16 "...this series..." it activates my siri... 😂😂😂😂😂😂😂😂😂
@usamarana5936
@usamarana5936 4 года назад
good typing speed i am impressed
@daverussell4052
@daverussell4052 3 года назад
Now its making more sense to use callbacks in javascript
@grownupgaming
@grownupgaming 2 года назад
Let's be honest. After you learn about function pointers, you still have great replay value due to the pose at 0:00
@robfei-u6b
@robfei-u6b Год назад
this is the best
@lorenzodiazdonzelli3048
@lorenzodiazdonzelli3048 3 года назад
noob question, why do u have '&' after const std::vector is it because you are taking the param as reference and not value? but why if you are not changing the variable? sorry if the questions sounds dumb, I'm just trying to learn
@lorenzodiazdonzelli3048
@lorenzodiazdonzelli3048 3 года назад
also, shouldn't the & sign be before the name of the param and not after the type or is it the same?
Далее
Lambdas in C++
11:54
Просмотров 340 тыс.
POINTERS in C++
16:59
Просмотров 1 млн
Watermelon magic box! #shorts by Leisi Crazy
00:20
Просмотров 2,6 млн
Stack vs Heap Memory in C++
19:31
Просмотров 568 тыс.
Why are function pointers useful?
6:43
Просмотров 30 тыс.
Type Punning in C++
13:20
Просмотров 157 тыс.
Threads in C++
11:35
Просмотров 362 тыс.
CONST in C++
12:54
Просмотров 404 тыс.
Track MEMORY ALLOCATIONS the Easy Way in C++
13:25
Просмотров 162 тыс.
Master Pointers in C:  10X Your C Coding!
14:12
Просмотров 309 тыс.
Using Libraries in C++ (Static Linking)
18:43
Просмотров 439 тыс.