Тёмный
Code for yourself
Code for yourself
Code for yourself
Подписаться
This channel is all about code. After more than a decade-long career in programming and designing software and a PhD in robotics and computer vision, I decided to have my own place on the Internet where I can chat about things I encountered throughout the years. The content will have more or less rigid courses on that or another programming language or technique, but might eventually morph into something less structured. Only time will tell. For now - welcome to this new journey and hope you will enjoy it with me!
Templates under the hood
6:57
7 месяцев назад
Why use templates in modern C++
12:32
7 месяцев назад
Const correctness in C++
10:02
Год назад
C++ classes: the basics
13:24
Год назад
1000 subscribers AMA answers
20:37
Год назад
1000 subscribers AMA
1:02
Год назад
CMake - the essential package
27:54
Год назад
Homework: the guessing game
1:49
2 года назад
Комментарии
@ozimandias1858
@ozimandias1858 3 дня назад
Буду откровенен, пересматривал 4 раза, и все рано не во всем разобрался. Так и не понял, для чего нам сохранять переменные с каким-то текстом. Однако, отличное видео - нужно просто приложить немного усилий. Мне, кажется, ролика хватит, чтобы понимать 90% cmake файлов. Все четко, и без воды
@CodeForYourself
@CodeForYourself День назад
Дякую за хороші відгуки! Стосовно змінних, загалом всі змінні в cmake це просто текст. І більшість цього тексту зберігається в кеші який потрібен для того щоб зберігати конфігурацію між запусками. А все інше про за я розказую то наслідки цього.
@ozimandias1858
@ozimandias1858 День назад
@@CodeForYourself Да, только момент с кешем не уловил. Все остальное кристально. Особенно понравилась презентация на гитхабе. Я вот раньше просто смотрел, ничего не повторяя. Сейчас Вы сказали "не тупить" и выполнить все самостоятельно. Начал это практиковать. Времени намного больше занимает, но после ощущение будто сам все сделал. А если вопросы есть, гпт использую. Еще раз спасибо :-). Подписка, лайк
@CodeForYourself
@CodeForYourself День назад
@ozimandias1858 будьте обережні з гпт, адже він хронічно бреше. Будь які конкретні запитання можна також задавати тут або на гітхабі. Я відповідаю повільніше за гпт, але сподіваюсь що менше брешу 😅
@Pedro-jj7gp
@Pedro-jj7gp 13 дней назад
Very nice video, thank you! What do you use for the code and diagram animations at the end?
@CodeForYourself
@CodeForYourself 13 дней назад
Thanks for the compliments! Whenever you see code animations I use motioncanvas.io The rest of the animations, including the last diagram animation here about shared pointers, I make by creating images with the Apple's Freeform, import them into Davinci Resolve where I edit my videos, and do the rest of the animations there.
@erkamkocaer2097
@erkamkocaer2097 14 дней назад
why did you use virtual on Write functions for jpegio and pngio at the final example code?
@CodeForYourself
@CodeForYourself 14 дней назад
That is it make sure that when we call these functions we look up the actual functions to be called in the vtable. In the end of the example we pass a reference to an *IoInterface* object. So try to make sure you understand exactly what will happen when we call *Write* on such an object reference. Does this help?
@erkamkocaer2097
@erkamkocaer2097 13 дней назад
​@@CodeForYourself I understand what you mean but in the video you used "void Write(const std::filesystem::path& path, const std::vector<Color>& data) const override { std::cout << "Writing PNG to path: " << path << std::endl; }" function but on github you used "virtual void Write(const std::filesystem::path& path, const std::vector<Color>& data) const override { std::cout << "Writing PNG to path: " << path << std::endl; }" function for both png and jpeg. I expected and understood first function but did not understand second one.
@CodeForYourself
@CodeForYourself 13 дней назад
@@erkamkocaer2097 oh! Now I understand! Thanks for pointing it out! It's a bug I have on GitHub. We *can* have *virtual* and *override* for the same functions but generally we should just use *override* as the *virtual* is implied here. So basically what I'm trying to say is that *override* implies *virtual*. I'll remove *virtual* from my GitHub code as it was probably a copy-paste error on my side. Thanks again!
@CodeForYourself
@CodeForYourself 13 дней назад
@@erkamkocaer2097 I've updated the code on GitHub to not have *virtual* in the last example. Thanks again for bringing it up!
@erkamkocaer2097
@erkamkocaer2097 13 дней назад
@@CodeForYourself thank you for your attention. I like your cpp videos. They are really impressive.
@Sheeldzy
@Sheeldzy 17 дней назад
I’ve been watching your channel and following along from the start. This video just helped me tie a lot of concepts together. Many thanks, keep it coming!
@CodeForYourself
@CodeForYourself 17 дней назад
Thanks a lot! Happy to hear it was useful!
@PerriPaprikash
@PerriPaprikash 17 дней назад
why do a video? why not simple write a nicely written article that people can read at their own leisure, and one where you can correct the numerous issues raised on the cpp subedit
@CodeForYourself
@CodeForYourself 17 дней назад
That is a valid question. The main reason is that some people prefer a video format and a video allows me to do both, have a markdown article and a video. You can find the markdown under the video. The downside is of course that errors are harder to fix.
@richardbennett4365
@richardbennett4365 19 дней назад
Then, he changed it back again at 6:05. 😂😮😅😅😅
@CodeForYourself
@CodeForYourself 19 дней назад
@@richardbennett4365 Same explanation as for the first change. The blank T-shirt is the original recording and the “save the earth” one is the follow-up 😅
@richardbennett4365
@richardbennett4365 19 дней назад
Nice, and why did the presenter change shirts at 5:10???
@CodeForYourself
@CodeForYourself 19 дней назад
@@richardbennett4365 simple. I recorded everything and then, when editing found that the story wouldn’t add up. So had to re-record and add a part. But the old tshirt was already in the laundry basket 😅
@segfault4568
@segfault4568 19 дней назад
About the manual delete, I always get questions from friends about whether they should use delete on a raw pointer they got as a return value from a function inside some old C library, It is all super confusing for beginners. Usually Documentation have it mentioned as "non-owning". It's amazing to see how all over the place each library's cleanup methods are.
@CodeForYourself
@CodeForYourself 19 дней назад
@@segfault4568 yes, my experience exactly. That mess is exactly the reason for all the smart pointers 😬
@leonardodosanjoschaves6204
@leonardodosanjoschaves6204 20 дней назад
I am just about to develop a “tree container”. The video content is so useful as an overview, clear, straight and didactic. Thanks
@CodeForYourself
@CodeForYourself 20 дней назад
@@leonardodosanjoschaves6204 awesome! Glad to hear it was useful and good luck!
@leonardodosanjoschaves6204
@leonardodosanjoschaves6204 20 дней назад
I am enjoying so much this course playlist. Thanks!!!
@CodeForYourself
@CodeForYourself 20 дней назад
@@leonardodosanjoschaves6204 happy to hear that! 🙏
@JoseRomagueraM
@JoseRomagueraM 21 день назад
It's great that people got interested by memory management, but I fully disagree with the usage of smart pointers and garbage collectors as a reliable and performant way of managing memory. Those techniques assumes that every "object" has his own lifetime, witch is fundamentally false: When there's one, there's many. This affects performance because of memory fragmentation and loses capabilities. I highly recommend the talk of Ryan Fleury about Arena Allocators, it's mindblowing how simple and effective a linear allocator can be. I almost never think about memory management and have all the performance and reliability.
@CodeForYourself
@CodeForYourself 21 день назад
Arena allocators definitely have their use! However, if we allocate a lot of objects we will quickly need to manage memory in complex ways. This lecture targets largely the default behavior for beginners. I believe that using the heap for allocations should be completely fine in most domains. Also, heap implementations benefit from years of optimization and as far as I know they basically use arena like allocations for small objects. That being said, if one really writes a safety critical application and cannot use heap memory at runtime then yeah, we’ll probably need to allocate stuff from an arena. Also, I don’t agree with putting garbage collection and smart pointers in the same row. They are very different mechanisms. Smart pointers are definitely reliable and in case of a unique pointer have nearly no overhead. So if one wants to allocate on a heap, smart pointers are definitely a way to go.
@advik-b
@advik-b 22 дня назад
This is quality content, your channel is underrated bro
@CodeForYourself
@CodeForYourself 22 дня назад
@@advik-b thanks for your kind words! Spread the word then. Let’s fix it. 😅
@div0826
@div0826 22 дня назад
love this explanation
@CodeForYourself
@CodeForYourself 22 дня назад
Glad you liked it! 🙏
@bibekjha8129
@bibekjha8129 23 дня назад
loving these videos.
@segfault4568
@segfault4568 23 дня назад
Very Nice lecture, all my years I have always been a Composition over Inheritance supporter as well I knew that private inheritance can get the job done but never bothered to see how; example at 9:59 cleared the syntax and semantics up perfectly. ☺
@CodeForYourself
@CodeForYourself 23 дня назад
Glad it was helpful! 🙏
@pragyandahal7357
@pragyandahal7357 23 дня назад
Amazing content Igor, keep up the good work.
@CodeForYourself
@CodeForYourself 23 дня назад
Thanks! I’ll try my best 👌
@SanjeevKumar-nm7ps
@SanjeevKumar-nm7ps 24 дня назад
you always deliver a masterpiece related to C++. Thank you so much for sharing your knowledge :)
@CodeForYourself
@CodeForYourself 24 дня назад
@@SanjeevKumar-nm7ps thanks so much for your kind words! You make me blush! ☺️ Glad that it is useful to you! 🙏
@glaubercini
@glaubercini 25 дней назад
Great video, however I couldn't figure it out how you change your T-Shirt that fast 😄.
@CodeForYourself
@CodeForYourself 25 дней назад
Oh, that’s very easy. You just mess up in the script, spend a week editing, then see that it’s wrong and that you have to re-record parts. 😅
@jojify
@jojify 25 дней назад
Great. Do you have any udemy course in detail for c++. I would like to purchase it
@CodeForYourself
@CodeForYourself 25 дней назад
Not yet, but maybe some day once I finish a full course here.
@politejellydragon8990
@politejellydragon8990 25 дней назад
Nah man, RAII is there for a reason. There is no free lunch. It's an indirection that in many cases isn't necessary. Writing a quick free with a null check into a destructor is not hard. Smart pointers are great for some things, but a shared pointer is inefficient and a unique pointer is kind of obsolete in many cases. I think nuance would make this a bit better. They should not be your default move. You should always evaluate your options.
@CodeForYourself
@CodeForYourself 25 дней назад
Could you elaborate a bit on how unique_prt is obsolete? This is the first time I hear about it.
@segfault4568
@segfault4568 19 дней назад
How is Unique pointer obsolete? it executes the same instructions as Raw pointer, same size as well, Scott Myers even recommended them to be used in tight cycles. Shared pointer though not to be confused with Auto GC is still a deterministic destructor so plenty useful, the only inefficient thing I can recall about Shared pointer is that it is twice the size because of control block pointer.
@CodeForYourself
@CodeForYourself 19 дней назад
@@segfault4568 I have a similar view (thus my original question to the OP). As for the shared pointer the reference count is atomic if I remember correctly, which requires synchronization and therefore might cost additional resources and instructions.
@tirthasg
@tirthasg 25 дней назад
Nice explanation! By the way, what font-style, and colour-theme are you using? It looks pleasant to the eye!
@CodeForYourself
@CodeForYourself 25 дней назад
Thanks! The font is Fira Code. The theme that you see in the animations is a custom one that more or less resembles the default vscode one.
@tirthasg
@tirthasg 24 дня назад
@@CodeForYourself Thanks!
@CodeForYourself
@CodeForYourself 24 дня назад
@@tirthasg sure, anytime!
@alifimtiaj5206
@alifimtiaj5206 25 дней назад
Great explanation. Liked and subbed buddy
@CodeForYourself
@CodeForYourself 25 дней назад
Thanks so much! 🙏
@kompila
@kompila 25 дней назад
How can I not like this video. Thank you Igor.~
@CodeForYourself
@CodeForYourself 25 дней назад
Thank you so much! 😊
@cozycactus
@cozycactus Месяц назад
what fonts you use in terminal? i liked them
@CodeForYourself
@CodeForYourself Месяц назад
I’m not entirely sure which one I used back then but I have mostly converged on using Fira Code everywhere now.
@bsdooby
@bsdooby Месяц назад
I like your (semantic) separation of impl.. inheritance and polymorphic inheritance 🎉
@CodeForYourself
@CodeForYourself Месяц назад
@@bsdooby thanks! I think it makes sense to teach them as separate concepts altogether
@alexanderbolinsky6430
@alexanderbolinsky6430 Месяц назад
Fantastic explanations and visuals!
@CodeForYourself
@CodeForYourself Месяц назад
Thanks a lot for the compliments! 😌
@Pedro-jj7gp
@Pedro-jj7gp Месяц назад
Nice video! Why is the int* 8 bytes instead of 4 at 1:30?
@CodeForYourself
@CodeForYourself Месяц назад
@@Pedro-jj7gp that’s just the way it usually is on most modern systems: any pointer is 8 bytes. In the end this has to do with being able to address enough places in the memory if this makes any sense. That being said, other systems could theoretically have it be smaller or larger. Does this answer your question?
@Pedro-jj7gp
@Pedro-jj7gp Месяц назад
@@CodeForYourself It does, but I'm a bit confused as I was watching some other videos about vtables and they showed the vpointer taking up 4 bytes... I guess it could just be on that system.
@CodeForYourself
@CodeForYourself Месяц назад
@@Pedro-jj7gp it might be. But you can always check it on your system too. I’ve only ever seen 8-byte pointers on every system apart from really non-standard embedded boards. 🤷‍♂️
@Pedro-jj7gp
@Pedro-jj7gp Месяц назад
@@CodeForYourself Yup, you're right! I just checked using sizeof() both for a regular int* and a vpointer using reinterpret_cast<int*>() and both are 8 bytes. The video in question was 12 years old, maybe it was a 32-bit machine
@CodeForYourself
@CodeForYourself Месяц назад
@@Pedro-jj7gp sounds like a 32 bit system indeed. Glad that it makes sense now 👌
@SystemSigma_
@SystemSigma_ Месяц назад
Nice and clean overview. However, dynamic polymorphism is a very well known and old topic in C++. I would suggest deepening into static polymorphism for the next video. Keep it up, it is refreshing to see technical C++ stuff in RU-vid 2024
@CodeForYourself
@CodeForYourself Месяц назад
@@SystemSigma_ thanks! I actually put static polymorphism before this video, it’s right along a series of videos about templates: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-1Mrt1NM3KnI.html Still not the most modern thing but necessary to understand concepts down the line I believe. I also wanted to give an overview eventually of how to do the same things using both dynamic and static polymorphism on some concrete examples. But for that people need to be familiar with both. Does this make any sense?
@SystemSigma_
@SystemSigma_ Месяц назад
@@CodeForYourself It does indeed. I meant that modern c++ features (especially type traits) are really useful for making more robust static polymorphic code. Maybe instead of going too generic with topics, restricting the features scope may be more interesting for experienced viewers.
@CodeForYourself
@CodeForYourself Месяц назад
@@SystemSigma_ I agree that a more in-depth look would suit experienced folk better. My aim here, however, is to fill in the complete playlist that would tailor to somebody who knows nothing about C++ and guides them gently through all the main topics, providing the "why" for using what they learn along with enough information to dig deeper. Please see here for the full list to date: github.com/cpp-for-yourself/lectures-and-homeworks Maybe one day, I will finish the basic course and have some time to dig more in-depth into certain things. That being said, I feel that there is plenty of that type of content on RU-vid already, while the comprehensive courses that I've seen all fell a bit short of what I wanted to achieve here. But we'll see if my course is going to be helpful to anybody 😅
@CodeForYourself
@CodeForYourself Месяц назад
@@SystemSigma_ oh, and just in case you have not seen already, I _do_ talk about type traits a bit more in-depth here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-IQ62tA51Vag.html
@danielstromberg
@danielstromberg Месяц назад
Hi. I think I have the C++ part of this completed, and would like to submit it for testing. But I'm a bit lost on the git side of this. I tried to use the same git template instance, and put my fortune_celler.cpp in ~/src/Full-C++17-course/t/cpp-for-yourself/homeworks/fortune_teller/task in a fresh branch (I also tried it in the same branch), but upon push'ing that to origin, I just got the example_homework graded again. Any suggestions?
@McDonaldIbekwe
@McDonaldIbekwe Месяц назад
Thanks for the video. Please, can you focus more on Modern C++. Here are some: 1. Coroutine 2. Multithreading/Concurrency 3. Testing
@CodeForYourself
@CodeForYourself Месяц назад
@@McDonaldIbekwe ok, so there is one video on testing that I did before but it is not in-depth. As for coroutines I would have to use them in some real projects to be able to speak confidently about best practices that relate to them unfortunately. 🤷‍♂️ I will try to squeeze some multithreading in though at some point but I can’t say when just now 🤷‍♂️
@bsdooby
@bsdooby Месяц назад
structs do not need "public" inheritance; structs are public by default (sorry for being a PITA); you spare a few keystrokes ;)
@CodeForYourself
@CodeForYourself Месяц назад
Yes, you are totally right, but I much prefer to be explicit rather than implicit. My logic is that it is not a big deal to type one more word but it allows us to not think about which inheritance is going to be picked by the compiler implicitly should we omit that “public”. Does this logic make sense?
@zunoby
@zunoby Месяц назад
Чудова лекція. В майбутньому було б цікаво почути щось на тему concurrency, threads загалом.
@CodeForYourself
@CodeForYourself Месяц назад
Дякую! Радий, що сподобалось! Подивимось, взагалі план був про це розказати, але це така велика тема і в ній так багато чого відбувається, що я не впевнений що зможу її просто і добре пояснити. Але вона у мене в планах. 👍
@bsdooby
@bsdooby Месяц назад
nitpicking: if you use UML for you examples, the impl. arrow (realization of an interface) has a non-filled arrow head.
@CodeForYourself
@CodeForYourself Месяц назад
Yeah, I thought of fitting to the standard UML style but then left it at that considering that the tools I used for creating the visuals did not have a non-filled arrow 😅
@falol13
@falol13 Месяц назад
SPOILER: Wrapping everything up with the Image class example from the start was a very nice move 👍 I really enjoyed this lecture and will definitely recommend this further. Thanks a lot for your awesome content! 👏
@CodeForYourself
@CodeForYourself Месяц назад
Thanks! I’m really happy that that move clicked. It was a long video so I wanted to end at one consistent example that would be relatively close to real life. 🙏
@AzerAnimations
@AzerAnimations Месяц назад
Haven't watched this yet, but I know it is good! One of the best C++ creators out there for sure!
@CodeForYourself
@CodeForYourself Месяц назад
Thanks for your support and such a trust in me 🙏 But feel free to revise once watched 😉
@bsdooby
@bsdooby Месяц назад
true words
@CodeForYourself
@CodeForYourself Месяц назад
This video took A LOT of time to make. Just the script I had to rewrite like 3 times. So, if you like what you see, please share this video with your C++ inclined friends if you found this video useful. 🙏 And do leave a comment, this way this video will be shown to more people apparently 🤷😉
@GeorgiosMATZARAPIS
@GeorgiosMATZARAPIS Месяц назад
Pure joy. Thanks!
@CodeForYourself
@CodeForYourself Месяц назад
@@GeorgiosMATZARAPIS thanks man 🙌
@akshaypratap4123
@akshaypratap4123 2 месяца назад
You have a very friendly face 🌞. I imagine it would be difficult for you to intimidate someone or to scold children
@CodeForYourself
@CodeForYourself 2 месяца назад
@@akshaypratap4123 that’s not how I think I am usually perceived at all. Especially when I’m coding. 😅
@rishiniranjan1746
@rishiniranjan1746 2 месяца назад
Could use dockerfile also to preinstall all gtest/grpc libs
@rishiniranjan1746
@rishiniranjan1746 2 месяца назад
Best explanation ever found for cmake
@CodeForYourself
@CodeForYourself 2 месяца назад
@@rishiniranjan1746 thanks! This means so much to me! 🙌
@BISONBOT94
@BISONBOT94 2 месяца назад
I am new to C++ templates and ran into this exact issue about an hour ago. This video helped me a lot, thanks!
@CodeForYourself
@CodeForYourself 2 месяца назад
@@BISONBOT94 awesome! Glad I could help out! 🙏
@UvUtkarsh
@UvUtkarsh 2 месяца назад
I wonder how the templates are used in data structures in STL (for ex: vector) so that it not only works with primitive data types like int, float,etc. (for which can do the template specialization) but also with user defined classes/structs, which is not known before hand. Any ideas ? @CodeForYourself
@CodeForYourself
@CodeForYourself 2 месяца назад
@@UvUtkarsh generally the code is written in such a way that as long as the provided types follow some form of an interface they should work. They also use traits and partially specialize classes based on what those traits tell about the provided type. I might do an in-depth look into this later if there is interest
@isfandyar3937
@isfandyar3937 2 месяца назад
what would you do with template class
@CodeForYourself
@CodeForYourself 2 месяца назад
There is an example of this towards the end of the video. Does that answer your question? Or should I give a better example? How can I make it better?
@CodeForYourself
@CodeForYourself 2 месяца назад
@@isfandyar3937 also, I cover this extensively in this video: Why use templates in modern C++ ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-1Mrt1NM3KnI.html
@xavierfrazao1469
@xavierfrazao1469 2 месяца назад
Great explanation. Thank you
@CodeForYourself
@CodeForYourself 2 месяца назад
Glad you liked it! 🙏
@SystemSigma_
@SystemSigma_ 2 месяца назад
If I'm not mistaken, this only helps speeding up compilation times due to the explicit template specialisation. Still, what other benefits do I get by splitting template declarations and definitions?
@CodeForYourself
@CodeForYourself 2 месяца назад
I guess you're right to a degree but there is more to it. Explicit template instantiation (different from specialization) does indeed help the compile times. It helps because without it, the code would live in header files and so would be copied to any translation unit that includes that header, leading to the compiler needing to compile all of those instances on their own. If we put the code into a source file (and for that we need an explicit template instantiation) we will only compile the code once and link it to the places where it is used instead. Does this make any sense? Now as to other benefits, one big downside of header-only libraries, apart from compilation times, is that all the implementation actually lives within the header files. Meaning that if we want to distribute our library to other people we essentially have to distribute source code. So in the end, we have a sort of a tradeoff, header-only libraries are quite simple to use but might lead to long compile times as well as to needing to show our source code to anybody using our library. I talk about this at length in the video about libraries here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Lxo8ftglwXE.htmlsi=JYNvd_2i6GLjfdvv
@SystemSigma_
@SystemSigma_ 2 месяца назад
I'm perfectly aware of the standard benefits of splitting declaration and definition.. Still, for templates I really don't think it's worth the typing effort (if you're outside a smart ide) 😅 I guess the most valid point is only hiding the source code for distribution 😊
@CodeForYourself
@CodeForYourself 2 месяца назад
@SystemSigma_ sometimes the compile times are important too. Some years ago I added a couple of explicit instantiations in a code base to save about an hour compile time 😅 I think if we *know* the types we’re about to use, then I would go for a compiled library as opposed to a header only one. It works also as an additional check for my design to a degree 🤷‍♂️
@SystemSigma_
@SystemSigma_ 2 месяца назад
@CodeForYourself yeah, I used it with quite a success in a few embedded projects, but, of course, every project is different so 🥲
@CodeForYourself
@CodeForYourself 2 месяца назад
@@SystemSigma_ yeah, I agree. 🙂‍↕️
@CodeForYourself
@CodeForYourself 2 месяца назад
Thanks a lot for watching, folks! Don't forget to share any thoughts you might have on this (or anything else)! 🙏
@yousefsaddeek
@yousefsaddeek 3 месяца назад
CMake Deez nuts
@Maximus98245
@Maximus98245 3 месяца назад
Great video! One thing that bothered me a bit was usage of "<typename ClassT> to specify template parameter. The parameter has nothing to do with class, it could be just as easily called <typename T>, the word "class" gives a wrong impression, at least to me. Thanks!
@CodeForYourself
@CodeForYourself 3 месяца назад
Ok, I agree with you that ClassT doesn’t hit the mark. What I prefer doing generally (when I cannot use concepts) is to give the template parameters meaningful names. Considering that this function is very illustrative and doesn’t really have a proper purpose it is hard to pick such a template parameter name, meaning the one that actually makes sense. So here I picked the ClassT as a substitute but I agree that it is a bit stupid and if I would have thought longer about it I probably would have just used T here. Thanks for your comment!
@PixelThorn
@PixelThorn 2 месяца назад
For the win, my man
@francescobenacci6611
@francescobenacci6611 3 месяца назад
@10:57 when we call DoSmth(number) i didn't expect the parameter type to be int&. Why is that, and not simply int? After all, it will be copied...
@CodeForYourself
@CodeForYourself 3 месяца назад
Unfortunately the answer to this comment is more complicated than I would like it to be. It has to do with how overload resolution is taken care of in C++, which is not trivial: en.cppreference.com/w/cpp/language/overload_resolution But the rule of thumb, at least the way I think about it, is that if we have a local object the compiler will prefer passing it by reference if an appropriate function overload exists. During this some implicit conversions can take place as well as some copies performed. My recommendation would be to write a simple example with some Foo function that has various overloads and see what the compiler does in each case to build more intuition. That being said if somebody who can explain it better stumbles upon this comment, I would like to find a nice and simple explanation for the future. 😅
@francescobenacci6611
@francescobenacci6611 3 месяца назад
@@CodeForYourself thank you, i really appreciate the answer, it surely provides a good starting point for me to try and understand this :) Keep up the great work, i discovered your channel with this video, and decided to start the whole course from the first lesson, even if I'm familiar with some of the basics of C++
@CodeForYourself
@CodeForYourself 3 месяца назад
@@francescobenacci6611 thanks for the kind words! Please mind that the first videos have a slightly different style from this one. I guess I converged to a style like this some time around the cmake video 😅
@segfault4568
@segfault4568 3 месяца назад
Universal Reference gang member Here, Scott Myers most loyal soldier.
@CodeForYourself
@CodeForYourself 3 месяца назад
Welcome 😅