Templates in C++

Patreon ► / thecherno
Twitter ► / thecherno
Instagram ► / thecherno
Discord ► thecherno.com/discord
Series Playlist ► thecherno.com/cpp
Thank you to the following Patreon supporters:
- Samuel Egger
- Dominic Pace
- Kevin Gregory Agwaze
- Sébastien Bervoets
- Tobias Humig
- Peter Siegmund
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

Пікірлер: 585

  • @AhmedTahagg
    @AhmedTahagg4 жыл бұрын

    "By no means is this going to be the only video I make on templates" - The Cherno 2017

  • @PwnySlaystation01

    @PwnySlaystation01

    4 жыл бұрын

    Hah just came here to say this

  • @GoatTwinkie

    @GoatTwinkie

    4 жыл бұрын

    F

  • @joestevenson5568

    @joestevenson5568

    4 жыл бұрын

    :(

  • @alltheway99

    @alltheway99

    4 жыл бұрын

    Could use more videos on templates 🙂

  • @josephs.7960

    @josephs.7960

    3 жыл бұрын

    Well that was a fucking lie

  • @sigmareaver680
    @sigmareaver6802 жыл бұрын

    For all the novices out there, I think there's one important thing he overlooked regarding using templates. With templates, you must either write AND use them inside a SINGLE source (cpp) file, OR you must write them ENTIRELY inside a header file. Unlike a regular function or class, you can NOT declare them inside a header file and then define them inside a source file. The linker won't be able to link the templates if you do.

  • @Austin_Rummel

    @Austin_Rummel

    Жыл бұрын

    Thank you! I was just about to do that.

  • @rretro2042

    @rretro2042

    11 ай бұрын

    Also you could write the declarations inside a .h header file and the definitions inside .tpp file

  • @techwithdipufrom0ton621

    @techwithdipufrom0ton621

    6 ай бұрын

    This video reduces the ambiguity about templates in C++ which was increased by other video tutorials. Thanks bro.

  • @piyushudhao597

    @piyushudhao597

    6 ай бұрын

    Can you separate the declaration and implementation in hpp and cpp files, and then include the cpp file at the end of the hpp file? Its technically the same thing but more organized i guess.

  • @kiara_kb8214

    @kiara_kb8214

    2 ай бұрын

    Ok

  • @baaryl
    @baaryl6 жыл бұрын

    I love this series. Motivated me to learn c++ and just got my first job as a software engineer. Keep it up!!!

  • @greatbullet7372

    @greatbullet7372

    6 жыл бұрын

    love to read that :)

  • @radoznalipustolov2693

    @radoznalipustolov2693

    6 жыл бұрын

    Congratulations! If it's not the secret, what kind of software development you do?

  • @padelafterdark

    @padelafterdark

    6 жыл бұрын

    what resources did you use to learn C++ and what techniques did you do to learn it? Thanks

  • @baaryl

    @baaryl

    6 жыл бұрын

    Nikola013 First of all I have no idea how to reply directly to your comment - so sorry for that. Anyway, this in not a secret :D I work in telecommunication

  • @baaryl

    @baaryl

    6 жыл бұрын

    Mark Tilbrook Just like befor dont know how to reply to your comment directly. Nothing special at all. Two books (one of authors was Stephen Prata, "professional c++" Solter and Kleper ), some videos like this and compiler and build some simple app (e.g calculator). Next step was to take part in c/c++ academy (it's kind of course) organised by the company in which I work now :)

  • @myj313
    @myj3133 жыл бұрын

    I know he’s an expert in C++ because he can talk about single concept for ~20 min, where every second counts 👍

  • @mantaz3068

    @mantaz3068

    3 жыл бұрын

    I think I never watched a 20 min video about a single concept without skipping any part before this

  • @typeterson8376

    @typeterson8376

    2 жыл бұрын

    I judge how good of a teacher a KZreadr is by whether or not I need to put their videos on 1.25x speed, because some are just too slow of speakers of too verbose. His flow of information seems to be just right.

  • @dennisorbison7318

    @dennisorbison7318

    Жыл бұрын

    you know when you are a noob when you need every second to understand a concept.

  • @bulentgercek

    @bulentgercek

    Жыл бұрын

    @@dennisorbison7318 If you want to learn something, you have to start with the basics. Otherwise, you will have memorized, which will cause the knowledge to be erased from your mind over time. So learning something that works for you always requires starting from the basics. The person who learns should not have an ego anyway. The word noob is an expression of the self-conceit of the person who uses it. Because no matter how much you learn, there is always something to learn in the details, even in a subject you know very well. Learning has no end. Also, no matter what your mastery level is, you're always going to solidify yourself by repeating the basics. In short, you are always a student. In other words, saying Noob to someone else is a sign of smugness also It is a sign of a lack of self-confidence.

  • @dennisorbison7318

    @dennisorbison7318

    Жыл бұрын

    @Bulent Gercek I think I am missing context or something, or somebody is missing context, because I am so confused, lol. Did I call somebody a noob? I am pretty sure I was using the word "you" in the general sense, not at anyone specifically. I commented haphazardly as to something I can personally relate with. Bruh, what is up with the assumptions? It's all right though. I forgive you for looking too deep into something and drawing out conclusions with very little context.

  • @VadimMelnicuk
    @VadimMelnicuk5 жыл бұрын

    Simply, the best C++ lessons in existence.

  • @bgzdevtips3762
    @bgzdevtips37626 жыл бұрын

    Another reason you shouldn't want to go too crazy with templates is compilation times. As cherno said, you're basically having the compiler write code for you. If you start having your compiler write a ton of code for you, then be prepared to wait a bit longer for your program to compile.

  • @ags0004

    @ags0004

    5 жыл бұрын

    Yeah, and worse than that is that headers cannot even be cached for multiple translation units. For each translation unit, you have to generate each header, even if that header was already generated before. This is one of the greatest problems an inefficiencies with the whole header system. I also feel like precompiled headers are sort of a hack rather than a solution to the problem...

  • @jukit3906

    @jukit3906

    2 жыл бұрын

    @@ags0004 I wonder how will C++20 modules turn out

  • @someone1089
    @someone10895 жыл бұрын

    Template = compile time polymorphism I don't like overuse of template, debugging is a nightmare. I have seen this horror myself.

  • @ycombinator765

    @ycombinator765

    4 жыл бұрын

    TMP will be even harder Wait for it

  • @vladlazar94
    @vladlazar946 жыл бұрын

    Great work as always! Your vids are on a totally different level! :D

  • @koobyroory
    @koobyroory6 жыл бұрын

    I love your series! I was having trouble in my C++ class and my TA suggested I should watch your videos. It has helped immensely

  • @rajatpai5048
    @rajatpai50485 жыл бұрын

    The content of this series very apt and rich. I am recommending this to my friends. Thank you for doing this.

  • @ShivamSingh-ue2qi
    @ShivamSingh-ue2qi6 жыл бұрын

    Really appreciate your series.. The way you explain things is so simple and effective

  • @namahshrestha3226
    @namahshrestha32266 жыл бұрын

    You sir are amazing..we need more from you. Please do not stop making videos

  • @creativeclaude5304
    @creativeclaude53045 жыл бұрын

    woow amazing! I love how you actually put it into code and shoe us how its actually running. My instructor would only show it on whiteboard and I could not understand it but, seeing it in code helps so much!

  • @yellowlegend245
    @yellowlegend2455 жыл бұрын

    This is a magical! the ease you explained one of most confusing and complicated topic is brilliant. pls keep going

  • @respawn_101slab2
    @respawn_101slab24 жыл бұрын

    Amazing videos, just started watching the channel. I plan to watch every posted video. Keep it up!

  • @raf.nogueira
    @raf.nogueira6 жыл бұрын

    I was trying to understand this Templates for such long time, and only now i understand thank you very much !

  • @guozhengdai2247
    @guozhengdai22476 жыл бұрын

    Thanks for this series. I have learned a lot from you!

  • @paintfortauva
    @paintfortauva3 жыл бұрын

    This is the first video i've seen from this channel and i can't stop smiling at how easy he has explained templates! i'm so excited i finally get it! well done mate. great video. subbed

  • @milesemanuelpaavola7994
    @milesemanuelpaavola79943 жыл бұрын

    Thank you very much for the tutorials, they are helping me immensely with my Electrical Engineering Studies. This is the 2nd semester I have sourced your tutorials during cram sessions and they have helped. :-D

  • @Light-wz6tq
    @Light-wz6tq6 жыл бұрын

    Best video about templates (Your series are awesome)

  • @nyctophilic1790
    @nyctophilic17903 жыл бұрын

    this is probably the best tutorial i have watched, very intuitive. Awsome work brother.

  • @voodoomotion5855
    @voodoomotion58554 жыл бұрын

    Excellent, I think this will help me a lot in what i'm currently developing! Thanks so much for your great tuition :)

  • @noctua7771
    @noctua77716 жыл бұрын

    You make learning C++ so easy and entertaining Keep it up!

  • @brandonflores7419
    @brandonflores74192 жыл бұрын

    Your videos on c++ are AMAZING! Everything that my professor confused me on was ironed out in these 10-20 min videos. Thank you so much🥹

  • @fragmister
    @fragmister2 жыл бұрын

    I love these video like documentations of individuals aspects of C++. Please keep making these, I love them.

  • @jackthehammer2245
    @jackthehammer22456 жыл бұрын

    Thanks for the intro for templates. Especially what really happened under the hood. Looking forward to see more of these coming!

  • @doingsneakypeakylike
    @doingsneakypeakylike6 жыл бұрын

    you make it so easy to understand! Please continue with more c++ vids. thank you :)

  • @TheDrewCrawford
    @TheDrewCrawford Жыл бұрын

    These videos are amazing. I spent a whole day trying to figure out how to create an array of an unknown size in a class, only to give up and move on. I see now how it can be possible. So very well explained. This series is getting me though my college courses. Thank you for sharing your knowledge.

  • @orocimarosay1447
    @orocimarosay14476 жыл бұрын

    best tutorials ever please make more since I can't find anywhere else such detailed and advanced information and this information is what can make me a good programer

  • @freddo1230
    @freddo12306 жыл бұрын

    Really great video, thank you! Explained with such clarity.

  • @SuperTravianPlayer
    @SuperTravianPlayer5 жыл бұрын

    Awsome video! I love the chill vibe and your voice is great... =)

  • @gabrielgraf2521
    @gabrielgraf2521 Жыл бұрын

    Wow, I think this was the cleanest sum of templates I have ever seen. Thanks a lot!

  • @helgabartok9755
    @helgabartok9755 Жыл бұрын

    Love ya 😍😍😍 and of course your series. Every sec worth a treasure!!!

  • @TM-su7vu
    @TM-su7vu2 жыл бұрын

    Very simple and clear. I'm glad that I found your channel. Thanks!

  • @darshandhande8903
    @darshandhande89035 жыл бұрын

    This is one of the best videos of this series!

  • @matiassandacz9145
    @matiassandacz91455 жыл бұрын

    IMPRESSIVE explanation. Very very VERY clear. Thank you.

  • @ericdecolsales3066
    @ericdecolsales30666 жыл бұрын

    Fantastic class. The basics of templates got so easy now.

  • @ashish1122000
    @ashish11220004 жыл бұрын

    Your videos are the best. Never stop making 'em.

  • @BeingHumanMusic
    @BeingHumanMusic3 жыл бұрын

    your delivery is really superb sir. Didn't see anyone like you.

  • @mbwilding
    @mbwilding2 жыл бұрын

    Easily the best C++ resource on KZread, thanks man!

  • @DanielLiljeberg
    @DanielLiljeberg6 жыл бұрын

    The thing I loved back when I started with C++ and learnt about templates (although the syntax can understandably look like drunk talk to people) was the fact that this is NOT some dynamic thing based on some shared base object the entire language uses but still enables you to create equally or more flexible code. By having the compiler generate the needed code for each type you use your templates with you basically add no extra runtime cost. That was awesome to young me. Another great side effect of how templates work and the fact that the template doesn't actually "exist as code" is that you can have a huge library of templates and it would not actually grow your binary a crazy amount unless you use them all. If it instead was a hughe library of "actual code" your binary would contain them all even if you only used a few of them.

  • @HermanWillems

    @HermanWillems

    5 жыл бұрын

    Fuck yeah C++ is amazing. I makes you feel in control. Understand what happens underneath. You need to know the tradeoffs of certain choices. It has a higher learning curve. But when you manage to learn it... and understand the tradeoffs of things inside the language. It feels like you can do anything. :) Unlike Managed languages or scripts it feels like there is hell of alot unknown black magic going underneath. And that just feels weird. I personally don't like that.

  • @PumpReactivationProject

    @PumpReactivationProject

    5 жыл бұрын

    @@HermanWillems C++ is amazing indeed. I was doing some lwjgl in java and it was all cool, I thought "Java is so amazing" and then I've stumbled upon decoding images and working with file formats. Oh... I cant use unsigned type... Oh... I can't treat array of bytes as array of ints, I need to iterate through and do a lot of bit shifting. C++ is hard - memory management, mix of different programming paradigms, namespaces, memory allocation, but at the end of the day it gives you power to control your program. Can't imagine going back to java now.

  • @tomhollins9266
    @tomhollins92665 жыл бұрын

    A VERY clear explanation of templates. I will point newbies to your channel.

  • @coltenpulis6679
    @coltenpulis66792 жыл бұрын

    i am sitting at work doing code reviews and watching your videos lmao you are a lifesaver

  • @GFXNever
    @GFXNever6 жыл бұрын

    As a matter of fact, the templates system is turing complete - that means you can actually implement ANY computer program using templates (and that program will run at compile time). Great video !

  • @stewartzayat7526

    @stewartzayat7526

    6 жыл бұрын

    GFXNever What do you mean by 'using templates'? It's turing complete even without them, so that doesn't make sense to me.

  • @jakobhellermann6974

    @jakobhellermann6974

    6 жыл бұрын

    GFXNever as a matter of fact, the x86 mov instruction is Turing complete ;)

  • @MsJavaWolf

    @MsJavaWolf

    4 жыл бұрын

    @@stewartzayat7526 C++ is of course Turing complete at RUNTIME, but with template metaprogramming you can compute anything that you want at COMPILE time. An example that is not template meta programming: constexpr int a = 7 + 8; the compiler will not generate code that moves 7 and 8 to registers and adds them, it will simply add it at compile time and the code will be a = 15; so no calculation has to run at runtime. Template metaprogramming is similar to that, but much more powerful.

  • @Neko_Void

    @Neko_Void

    4 жыл бұрын

    Oh yeah, i read an article about this and how the template system it's theoretically undecidable, but there were problems with the proving method, i didn't pay much attention to it so i'm not sure

  • @Kitulous

    @Kitulous

    4 жыл бұрын

    @@stewartzayat7526 I've seen somewhere how people created a power function (a^b) that evaluated powers at compile time.

  • @kevinchau5336
    @kevinchau53366 жыл бұрын

    wow.... I'm sooo glad I clicked on this video! thank you so much for the clear explanation!

  • @MrMunoz-xp2ry
    @MrMunoz-xp2ry3 жыл бұрын

    Sometimes when i watch these videos, I replay that mind blown video in my head.

  • @malindasulochana7258
    @malindasulochana72586 жыл бұрын

    dude, you are awesome. brilliant explanation and simple, keep up the good work. (Y)

  • @LeandroNunesLeandroN
    @LeandroNunesLeandroN4 жыл бұрын

    "This can get really crazy, really quickly" is my favourite quote here.

  • @p30hacker
    @p30hacker Жыл бұрын

    best explanation of templates I have ever seen. thanks cherno!

  • @hassanedds3785
    @hassanedds37853 жыл бұрын

    That's the best explination I came across so far , thank you

  • @sinned_rev
    @sinned_rev4 жыл бұрын

    Nice to see that you got straight to the point, where I was able to understand templates after having 90 minutes of programming lecture in the university without understanding a single thing :D

  • @jonweinraub
    @jonweinraub2 жыл бұрын

    What a much better introduction to templates than just explaining how vector foo or something.

  • @Jumph96
    @Jumph963 жыл бұрын

    Thanks for making this video, I finally have an idea on how this template thing works

  • @harshkn
    @harshkn6 жыл бұрын

    Was waiting for this. Please make more template videos soon :D

  • @devchannel5232
    @devchannel52323 жыл бұрын

    Man, you got me with this nice tutorial, i subscribed! Thanks a lot.

  • @rishikeyyadav5717
    @rishikeyyadav5717 Жыл бұрын

    Really loved this video...even stackoverflow kneeled down before you... thanks again.

  • @baltazarus3307
    @baltazarus33075 жыл бұрын

    You're genius! Thanks for this video!

  • @moeenkamali1288
    @moeenkamali12882 жыл бұрын

    best source of learning cpp ever. thanks man!

  • @oblivionronin
    @oblivionronin6 жыл бұрын

    Hey Cherno ! Love your videos ! Really well done, technical enough to be really usefull and really help out but also very well simplified ! you made a video serie on on OpenGL, I was wondering if you are planning on ever doing something on OpenCL and or Cuda, thoses languages are awesome, but coding examples in thoses are ussually pretty rare. keep up the good work !

  • @ahmedibrahim7585
    @ahmedibrahim75854 жыл бұрын

    Really the best video that explains templates. Thank you alot.

  • @maxmoeller3597
    @maxmoeller35972 жыл бұрын

    This class stuff got me low key excited

  • @ianpan0102
    @ianpan01024 жыл бұрын

    Best C++ series I could find on the internet

  • @MoTharwat-sw2dc
    @MoTharwat-sw2dc7 ай бұрын

    Clear, concise and straight to the point.

  • @ToxicityGameDev
    @ToxicityGameDev6 жыл бұрын

    Dude, please don't let this C++ series go for OpenGL, Hope to see them both continue. Keep up the great work!

  • @pixarfilmz4769

    @pixarfilmz4769

    6 жыл бұрын

    Yeah!

  • @ErikDaGreat

    @ErikDaGreat

    5 жыл бұрын

    he doesnt like game he likes game engine

  • @The_Codemaster144k

    @The_Codemaster144k

    Жыл бұрын

    @@ErikDaGreat he likes both

  • @sakshamdogra
    @sakshamdogra Жыл бұрын

    THIS IS THE BEST VIDEO TO EXPLAIN TEMPLATES. You just earned a subsciber.

  • @user-sd2en6pn3z
    @user-sd2en6pn3z4 жыл бұрын

    Why is it that nobody else seems to be able to explain c++ templates so clearly? I probably spent half a day struggling with this, then came upon this video and it was immediately clear. And even if I knew nothing about templates before seeing this, I think I still would have understood just as clearly. Thanks!

  • @runetimon
    @runetimon6 жыл бұрын

    Dude this video is perfect for some one not understanding templates! :D

  • @cooltuque
    @cooltuque2 жыл бұрын

    WOW I just understood a load of stuff I didn't before... Thx Cherno. Best tutorials ever...

  • @MadAustinite
    @MadAustinite4 жыл бұрын

    I just learned more in 18 minutes than reading the same thing over and over again in my textbook for over an hour. Thanks man!

  • @jonivanwin530
    @jonivanwin5306 жыл бұрын

    Hey Cherno, I love your work. Continue like this. I want to ask you if you could make a series of networking, from the basics. Like sockets, client server. Thank you for your work.

  • @johnadams7843
    @johnadams78436 жыл бұрын

    you won't find a better like to dislike ratio for coding tutorial than your channel, your tutorials are awesome, keep going!

  • @october3518
    @october35182 жыл бұрын

    I wouldn't have started learning C++ if it was not for your videos. I watched starting 18-20 vids then shifted to books because I really needed to clear few concepts. Now I understand a little bit better than past and m back !!

  • @prasannakumarkottakota68
    @prasannakumarkottakota68 Жыл бұрын

    Thank you, it is wonderful explanation!

  • @hamzaaitbourhim5321
    @hamzaaitbourhim53214 жыл бұрын

    This is the best C++ series I've seen so far.

  • @oblivionronin
    @oblivionronin6 жыл бұрын

    Hey cherno ! love the series keep up the good work ! any chance you will cover Threads in the future ? thatd be awesome ! i worked a lot with them in Java but they seem wildly different in C++ for the syntax and handling of them.

  • @sidewinder040
    @sidewinder0403 жыл бұрын

    Now I understand. A very clear explanation - Thank-you.

  • @asfandshakeel8427
    @asfandshakeel84275 жыл бұрын

    That is brilliant mate. Thanks!

  • @taherbensassi2626
    @taherbensassi26265 жыл бұрын

    your really make it look so easy ! thank you

  • @Nicolas-gq9vu
    @Nicolas-gq9vu6 жыл бұрын

    Was waiting for a template video !

  • @janingvar
    @janingvar2 жыл бұрын

    You explain things better than some highly rated C++ lecturers on Udemy.

  • @boywonder_YT
    @boywonder_YT Жыл бұрын

    Fantasitc way of explaing this, thank you

  • @tunisianleague2457
    @tunisianleague24574 жыл бұрын

    Finally, I got how this weird C++ code in unreal engine works thanks man you made my day!!

  • @boutalbimedchaker2534
    @boutalbimedchaker25344 жыл бұрын

    that was so amazing dude thamk you so much

  • @HellPet
    @HellPet2 жыл бұрын

    Solid video again. Would like to see one about your own implementation of enable_if and some usages!

  • @xarzu
    @xarzu7 ай бұрын

    Great job. Good explaination.

  • @luisalcaraz9090
    @luisalcaraz9090 Жыл бұрын

    I LOVE YOU!!! Thank you for making this video. You are the best. ❣😘😍

  • @satyajeetkumarjha1482
    @satyajeetkumarjha1482 Жыл бұрын

    the example used by you is really good.

  • @iamnotaleapord
    @iamnotaleapord5 жыл бұрын

    Really great videos, thank you sir

  • @henokvanni3831
    @henokvanni3831 Жыл бұрын

    I love the fact that the first time that he said the template definition i didn't understand, but then he wrote the code and when he repeated the definition i did understand what it meant. Thanks for the videos

  • @VarunArora14
    @VarunArora144 жыл бұрын

    Best video to easily understand templates . I tried GeeksforGeeks but this made me understand better at beginner level .

  • @RX7GSLSEowner
    @RX7GSLSEowner3 жыл бұрын

    Would like to see a video regarding template metaprogramming. That stuff is mind bending.

  • @saeed5508
    @saeed55082 жыл бұрын

    great examples, Thank you

  • @rocketleague2136
    @rocketleague21364 жыл бұрын

    thank you cherno. great explanation;

  • @thedrunknmunky6571
    @thedrunknmunky6571 Жыл бұрын

    Nice sofa. Looks very comfy.

  • @hosseinbiniaz9379
    @hosseinbiniaz9379 Жыл бұрын

    amazing, very well explained

  • @mistersir3185
    @mistersir3185 Жыл бұрын

    Cherno is an industry man that can also teach better than most college professors.

  • @davidl.castillo7517
    @davidl.castillo75174 жыл бұрын

    this guy is sooo amazing!!

  • @KarabauPlay
    @KarabauPlay Жыл бұрын

    Wow. C++ is so powerful. Lots of possibilities!

  • @user-bm6ck4pm2y
    @user-bm6ck4pm2y4 жыл бұрын

    Still rockin it, keep goin man

  • @samsbuilding3893
    @samsbuilding38932 жыл бұрын

    the way that u explain it bro just u r the G.O.A.T. in this game!