Function Pointers in C++

  Переглядів 374,795

The Cherno

The Cherno

День тому

Patreon ► / thecherno
Twitter ► / thecherno
Instagram ► / thecherno
Discord ► thecherno.com/discord
Series Playlist ► thecherno.com/cpp
Thank you to the following Patreon supporters:
- Dominic Pace
- Kevin Gregory Agwaze
- Sébastien Bervoets
- Tobias Humig
- Peter Siegmund
- Kerem Demirer
Gear I use:
-----------------
BEST laptop for programming! ► geni.us/pakTES
My FAVOURITE keyboard for programming! ► geni.us/zNhB
FAVOURITE monitors for programming! ► geni.us/Ig6KBq
MAIN Camera ► geni.us/t6xyDRO
MAIN Lens ► geni.us/xGoDWT
Second Camera ► geni.us/CYUQ
Microphone ► geni.us/wqO6g7K

КОМЕНТАРІ: 357
@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 3 роки тому
int (*f(float (*)(long), char *))(double);
@Simon-jw1ww
@Simon-jw1ww 2 роки тому
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 2 роки тому
@@Simon-jw1ww function pointers have nothing to do with smart pointers. For something like this you should use lambdas and std::function.
@kinggore5229
@kinggore5229 3 роки тому
Someone give this man a medal, pls.
@PythonPlusPlus
@PythonPlusPlus 5 років тому
Who else is binge watching the playlist?
@TheGermanLPGaming
@TheGermanLPGaming 5 років тому
yup.
@smurf123444
@smurf123444 5 років тому
me!
@abdulalhazred5924
@abdulalhazred5924 5 років тому
only you, I'm just looking for some specific stuff
@edencheung8468
@edencheung8468 4 роки тому
Mememememe
@RamiAwar
@RamiAwar 4 роки тому
> Netflix
@BlackJar72
@BlackJar72 6 років тому
A+++++ content! I've been wanting to learn more about function pointers.
@louarn
@louarn 5 років тому
It's C++, not A+++++.
@richardlighthouse5328
@richardlighthouse5328 5 років тому
@Louarn he meant grade: A+++++
@louarn
@louarn 5 років тому
@@richardlighthouse5328 It was a joke
@vertigo6982
@vertigo6982 5 років тому
Now on to function objects, and functors!
@diamaudixaudioltd.299
@diamaudixaudioltd.299 2 роки тому
needs more +'s
@neo-babylon7872
@neo-babylon7872 4 роки тому
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!
@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
@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.
@samsturdi
@samsturdi 5 років тому
Hey dude, just wanted to let you know you are my go to for getting foundations of principles. You've helped me out several times. Thanks so much!
@alik250
@alik250 5 років тому
This is the greatest coding tutorial series iIve ever seen. If only somebody as talented and knowledgeable about the subject would make similar styled tutorials for other coding languages, the world would be a much better place
@vvanchesa
@vvanchesa Рік тому
Found your c++ series now. To learn C++ and dive in quickly your videos are absolute great!
@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.
@AswinJP
@AswinJP 4 роки тому
Very few people do such an excellent job at this. Thank you Cherno! :)
@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
@jun7452
@jun7452 29 днів тому
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!
@ryanbinter2447
@ryanbinter2447 5 років тому
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 Рік тому
@@reenamola2162 cherno goes into proper detail, Bucky just scratches the surface
@masterproducts0
@masterproducts0 6 років тому
The simple explaination makes it very helpful! :) Thank you for this series and keep going like you do.
@nuriya9000
@nuriya9000 5 років тому
Thank you so much!! I was revising cpp and I got stuck here. This really helped me a bunch. Definitely subscribing!
@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.
@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.
@AxElKo440
@AxElKo440 6 років тому
Man, it's awesome, thank you so much for these lessons ♥
@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.
@annahakobian7371
@annahakobian7371 5 років тому
best c++ tutorials, thanks man
@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
@greatbullet7372
@greatbullet7372 6 років тому
Im so in love with u that u continue this series
@Fol2ey
@Fol2ey 3 роки тому
Dude. Your explanations are saving my life right now!
@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.
@NeoKailthas
@NeoKailthas 3 роки тому
"Gentle introduction" lol 😆
@jakobhuetter
@jakobhuetter 3 роки тому
Love your videos! Helping me a lot with my university stuff!
@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....
@momentswithjireh3921
@momentswithjireh3921 3 роки тому
Thank you Cherno for this super fantastic explanation!
@Hasansaid51
@Hasansaid51 3 роки тому
That explanation at 1:04 just clicked in my head and I didn’t even watch the rest of the video. Thanks brotha 🙏🏾
@haven4512
@haven4512 3 роки тому
Thanks for making these videos, they really help a lot!
@Katelomjaria
@Katelomjaria 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
@ianpan0102
@ianpan0102 3 роки тому
Brilliant content. I can't thank you enough, Cherno!
@muhammadarslanrana942
@muhammadarslanrana942 3 роки тому
with this we can implement map(), reduce(), filter() functions as well.
@sunilpatro1047
@sunilpatro1047 4 роки тому
Awesome explanation. I did search a lot but couldn't understand. But now all my doubts are clear after watching this video. Great content.
@onyinyechichukwuma689
@onyinyechichukwuma689 2 роки тому
The best C++ explanations EVER! Thanks!
@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!
@Vermilicious
@Vermilicious 4 роки тому
Passing functions is super useful sometimes. It's a concept I first saw using JavaScript. It's really cool that you can do it in C++ (for a while) now.
@frederickmloka5454
@frederickmloka5454 4 роки тому
Thanks for demystifying subject
@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
@samuelmaucaille702
@samuelmaucaille702 5 років тому
Bro you're a fantastic teacher! thanks a lot!
@laurentiudobrescu9045
@laurentiudobrescu9045 6 років тому
Good work ! I need this video , it's awesome !
@WhosTheBossHD
@WhosTheBossHD 4 роки тому
In C# i use Action for function pointers. Function pointers are great for Publish/Subscription type of projects.
@DiogoManteu
@DiogoManteu 9 місяців тому
Such a great explanation with examples.
@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.
@MohdFaisal-ie6mo
@MohdFaisal-ie6mo 6 років тому
Keep up the good work. UKposts need experience coders like you.
@santhoshnagarajs3489
@santhoshnagarajs3489 6 років тому
finally i understand why there is need for function pointers!! thank you .
@hlrbBrambleX
@hlrbBrambleX 2 роки тому
I just realized this is how callback function works. Amazing!
@Ebiko
@Ebiko Рік тому
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
@danielc4267
@danielc4267 5 років тому
Great content. Thank you cherno
@leducphuclong
@leducphuclong 2 дні тому
Thank you so much !! Great Teacher !!
@isaiaskaung8856
@isaiaskaung8856 5 років тому
Thank you so much for showing new tricks.
@VasaMusic438
@VasaMusic438 5 років тому
Great video, again !!! Thanks !!!!
@iteratedofficial
@iteratedofficial 2 роки тому
Probably the best c++ tutor on youtube
@avnishs.2514
@avnishs.2514 4 роки тому
Amazing video! Helped me understand better
@LAB_XI
@LAB_XI 3 місяці тому
Great as usual 🔥
@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++.
@naughtrussel5787
@naughtrussel5787 5 років тому
Thank you for cool vids. Plz don't stop.
@duchaolv5876
@duchaolv5876 2 роки тому
Every time I want to know something about modern c++, I come here. Good job Cherno!
@gunrunjk
@gunrunjk 5 років тому
I always enjoy your video.
@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
@rajeevsawant2281
@rajeevsawant2281 4 роки тому
Excellent Video's. Thank you. It would be very helpful if you could have an few famous problems related to the topic and maybe a solution video .
@Ash-ei9ku
@Ash-ei9ku 6 років тому
Clean cut
@diegomora997
@diegomora997 2 роки тому
Dude, you make me feel more exited about computer science
@mms0537
@mms0537 3 роки тому
I respect you dude
@zyulaikhaerhad
@zyulaikhaerhad 3 роки тому
Thank you!! You just saved me and my assignment from the due date
@chsu_
@chsu_ Рік тому
Thanks for your video!
@alexsece
@alexsece 5 років тому
Great job!
@daveski084
@daveski084 5 років тому
He's so cute, makes learning C++ that much better lol.
@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.
@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
@AngelTaylorgang809
@AngelTaylorgang809 4 роки тому
Start a data structure series please, greetings from Texas
@hankstalica1922
@hankstalica1922 4 роки тому
Excellent vid.
@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!
@adocarpel7770
@adocarpel7770 5 років тому
many thanks
@ChandraShekhar-by3cd
@ChandraShekhar-by3cd 5 років тому
Really Fantastic Explanationss...Great............PLEASE DO Post Videos Related to Design PAtterns and DATA Structure.
@joaocosta1894
@joaocosta1894 5 років тому
What is the difference between: void ForEach(const std::vector& values, void(*func)()) and void ForEach(const std::vector& values, void func () ) both work fine for me.
@qy4247
@qy4247 2 роки тому
Really good tutorial. Thx from China ❤
@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
@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.
@joseernestoguerrerocueva9916
@joseernestoguerrerocueva9916 Рік тому
mate i fucking love your series
@thesanctuary225
@thesanctuary225 5 років тому
You are the Master of C++...
@dpalmer4588
@dpalmer4588 5 років тому
So, like nested functions, essentially? very cool
@2012Misanthrope
@2012Misanthrope 5 років тому
Great C++ videos! Much appreciated. Is that an XPS 13 your using?
@Cyberfoxxy
@Cyberfoxxy 4 роки тому
GUI benefits greatly from event driven patterns. void(*onclick)(int x, int y); If nobody uses this syntax, what is my alternative?
@APaleDot
@APaleDot 4 роки тому
You should probably just use typedefs. So, if you had, let's say, a button class with an onclick event: typedef void(*ClickEvent)(int x, int y); class Button { public: ClickEvent onclick; } Then you could set each individual button's onclick by setting the onclick member directly: someButton.onclick = [ ] (int x, int y) { //some code here }; or: void clickHandler(int x, int y) { //some code here } someButton.onclick = &clickHandler;
@joseponce6250
@joseponce6250 2 роки тому
thank you!!
@lemonextract1325
@lemonextract1325 5 місяців тому
thank you
@charlesbenca5357
@charlesbenca5357 4 роки тому
What would it look like if we specify a template in void(*func)(int) ?
@charr6108
@charr6108 2 роки тому
OMG! did i just learnt lamda and function pointer in 10 minutes... awesome!
@cavelinguam6444
@cavelinguam6444 4 роки тому
really awesome
@trongnhantran3358
@trongnhantran3358 Рік тому
This blow my mind!!
@usamarana5936
@usamarana5936 4 роки тому
good typing speed i am impressed
@voiddeepstorage6533
@voiddeepstorage6533 2 роки тому
you should do a video about using variadic templates function pointers, its a really cool topic.
@phantomstriker7996
@phantomstriker7996 Рік тому
The name says it all. It points towards a function instead of a variable.
@user-rk9zx3lt8k
@user-rk9zx3lt8k 8 місяців тому
this lesson which involves some many technical things such us auto, vector, typedef, function pointer, reference, even iterator inside
@Simon-fu8sd
@Simon-fu8sd 2 роки тому
I just find this so cool
@jsnmad
@jsnmad 3 роки тому
C++ Callbacks! Nice
@Decco6306
@Decco6306 4 роки тому
wow A Programmer with awesome video quality that doenst use a Mac I appreciate that
Lambdas in C++
11:54
The Cherno
Переглядів 324 тис.
Templates in C++
17:58
The Cherno
Переглядів 568 тис.
why do void* pointers even exist?
8:17
Low Level Learning
Переглядів 296 тис.
Stack vs Heap Memory in C++
19:31
The Cherno
Переглядів 543 тис.
Why are function pointers useful?
6:43
CodeVault
Переглядів 27 тис.
Type Punning in C++
13:20
The Cherno
Переглядів 151 тис.
Threads in C++
11:35
The Cherno
Переглядів 347 тис.
are "smart pointers" actually smart?
9:44
Low Level Learning
Переглядів 66 тис.
Dynamic Arrays in C++ (std::vector)
14:14
The Cherno
Переглядів 366 тис.
SINGLETONS in C++
19:16
The Cherno
Переглядів 190 тис.