Virtual Functions in C++

Поделиться
HTML-код
  • Опубликовано: 1 янв 2025

Комментарии •

  • @greob
    @greob 7 лет назад +275

    There's no such thing as "minimal impact" in my opinion, there's impact or no impact. I'd rather avoid impact altogether. :P

    • @TheCherno
      @TheCherno  7 лет назад +737

      If you live your life without recognising levels of impact and absorbing some, you're not going to get anything done.

    • @greob
      @greob 7 лет назад +80

      I was just kidding, but the topic of optimization in programming is very interesting to me. ;)

    • @DarkLevis
      @DarkLevis 7 лет назад +104

      Some additional runtime costs are acceptable to make the COST of actually programming it smaller. And hay, people even use python to program which gives you a heavy runtime penalty compared to C/C++...

    • @kevycatminecraftmore7721
      @kevycatminecraftmore7721 7 лет назад +1

      Interesting.

    • @vighnesh153
      @vighnesh153 5 лет назад +30

      Let's say, I just touch your cheeks using a fingertip and then I slap you. Both are impacts. The first 1 will just hurt you mentally (some feeling of awkwardness) but the second 1 will hurt you both physically and mentally). You may ignore the 1st one and move on with your life, but you won't be able to forget about the second one for quite a while. I hope I have made my point.

  • @JuanPabloOrtizYax
    @JuanPabloOrtizYax 5 лет назад +717

    Brief explanation of uncovered topics (yet) in this video:
    Since strings is not a primitive type of C++ we need to import the header
    #include
    To use string without namespace std is like this:
    std::string MyString("hello")
    This is equivalent to:
    std::string MyString = "Hello"
    Pointer instances:
    new keyword returns a pointer
    std::string* MyString = new std::string("Hello")
    And if is a pointer you access their properties with -> instead of a dot (.)
    std::cout length()

    • @michamarzec9786
      @michamarzec9786 5 лет назад +35

      Thanks for explaining. Now it all makes sense.

    • @archsheep7772
      @archsheep7772 5 лет назад +10

      Thank you for your detailed explanation!

    • @carlosantoniogaleanorios4580
      @carlosantoniogaleanorios4580 5 лет назад +31

      Thanks, this was really helpful. There is one more thing that was not explained before (as far as I can recall). In the constructor of the player class, he uses a constant string "name", which he passes by reference (first, I don't understand why this has to be a constant or a reference) and then he goes on to add the colon and m_name(name). I think I have seen in some other tutorial series that this is the way to load a value into a constant but I am not sure now.

    • @allenguan6755
      @allenguan6755 4 года назад

      thank u bro, love u every much

    • @nendo502
      @nendo502 4 года назад +18

      So what's "Player(const std::string& name) : m_Name(name) {}" exactly? Could u give me a keyword of this stuff to search? I have no idea what it is and how to search it for details.

  • @milenkopizdic9217
    @milenkopizdic9217 4 года назад +345

    For the newcomers, my suggestion would be to watch "stack vs heap memory in C++", "how to create/instantiate objects in c++" and "the new keyword in c++" before watching this.

    • @vikkio88
      @vikkio88 3 года назад +7

      thanks man, this is exactly what I was wondering

    • @furki6449
      @furki6449 3 года назад +1

      thx :)

    • @aniketnegi2642
      @aniketnegi2642 3 года назад +1

      thanks man!

    • @rustyelectron
      @rustyelectron 3 года назад +1

      Thanks a lot.

    • @Hoppitot
      @Hoppitot 3 года назад +4

      also inheritance in C++ really clears up the class Player : public Entity

  • @luisantonioreyes9375
    @luisantonioreyes9375 4 года назад +229

    My English captions: "my name is HMO and welcome back to my syphilis gloss series".

    • @Till27_Spence
      @Till27_Spence 3 года назад +4

      This is fax, i just tried it 🤣

  • @bassbatterer
    @bassbatterer 5 лет назад +179

    One of my lecturers actually went and dissembled the function calls for a Virtual function and for non-virtual functions for us to look at. The Normal function call executed 4 assembly instructions where as the Virtual function call executed 6, the additional 2 were dereferencing the pointer to the function pointer in the Vtable and then dereferencing the function pointer in the Class-specific function list. The overhead of 2 extra x86 instructions is next-to unnoticeable compared to the penalty of setting up a new stack-frame (which you have to do for both anyway) so the performance hit really in negligible.

    • @jonnywright8155
      @jonnywright8155 4 года назад +5

      Excellent comment. I'm having an error now which mentions the vtable and I think I know what's going on now thanks to this explanation . Thanks!

    • @rutanshu85
      @rutanshu85 4 года назад +2

      Thanks for sharing!

    • @CWunderA
      @CWunderA 3 года назад +1

      Doesn't it matter how big your vtable is though?

    • @ronensuperexplainer
      @ronensuperexplainer 3 года назад +12

      Dereferencing the function pointer can cost you 1000 instructions, because RAM has a high latency.

    • @petersansgaming8783
      @petersansgaming8783 2 года назад

      @@ronensuperexplainer depends. Couldn't one develop a prefetcher for this problem to reduce memory latency?

  • @raoulbrigola5050
    @raoulbrigola5050 5 лет назад +22

    By far the best channel on youtube to learn anything about c++! Thanks a lot cherno!

  • @MilindNikose
    @MilindNikose 3 года назад +24

    To better understand his code, go through these topics first:
    1. String Class
    2. Initialisation list
    3. Arrow Operator
    4. New keyword

  • @nilsmelchert776
    @nilsmelchert776 7 лет назад +26

    Beautiful set of tutorials. Probably the best I've seen so far for any programming language.
    I also like how it is divided into the different episodes that you can watch whenever you are only interested in a specific topic.
    Thank you for your time and please keep going like this!

  • @undeadguy2
    @undeadguy2 2 года назад +4

    Figured id give you a thumbs up your 30 second explanation of what a virtual function does explained what my teacher could not do in 2 hours. Appreciate it sir.

  • @jonnyreh001
    @jonnyreh001 2 года назад +3

    You are the best Cherno. I am visiting your c++ series regularly. Basically when I run into a concept I need to get familiar with on the go :D

  • @serkanozturk4217
    @serkanozturk4217 2 года назад +7

    Personal notes:
    - Virtual functions help us to override functions in subclasses
    - Normally, without virtual functions, when you call a fucntion, that funtion is called according to the type the variable is declared, not according to the real type that variable points to(see video)
    - Virtual function helps you to call the proper fucntion, not according to the declared type, but according to the actual type it points to
    - Override keyword is used to specify that that function overrides another func in base class(u don’t have to use though)

  • @hamza.abdullah807
    @hamza.abdullah807 5 лет назад +53

    Guests: That's a very nice sofa, how comfy is it to sit on..?
    Cherno: No, it's just for the Aesthetics, I sit on the ground.

  • @FranciscoCrespoOM
    @FranciscoCrespoOM 4 года назад +7

    Most of the time I've seen a tutorial about virtual functions/vtables it works pretty well to make some diagrams on paper about how it works because it's such an abstract concept that in general people, especially newbies, find a hard time trying to understand what's happening under the hood.

  • @ishouldhavetried
    @ishouldhavetried 4 года назад +3

    Let me tell you, I've been going to school for Software Engineering, and I have taken a bunch of different languages. Not a single one of them I really understood, just got it well enough to pass the class. But ever since I've found your CPP series, it's really helped, and I think I finally "get" it. This is the first language where I'm able to code without having to look up the solution 5 minutes into trying. Thank you for this series!

    • @jscorpio1987
      @jscorpio1987 4 года назад +1

      I don’t know if it’s this guys videos that influence my feelings but I feel like C++ is the most intuitive programming language I’ve ever used. I feel like the newer higher level languages abstract things away to the point where they actually miss their goal of being easier, and wind up being much more confusing because there is so much going on behind the scenes that you never really know what exactly your code is doing.

    • @sripradpotukuchi9415
      @sripradpotukuchi9415 4 года назад +1

      @@jscorpio1987 +1

    • @weiss588
      @weiss588 2 года назад +1

      @@jscorpio1987 hell no

  • @work9167
    @work9167 3 года назад +2

    This is short and beautiful, man! Please, continue doing what you do now

  • @PirateDion
    @PirateDion 4 года назад +2

    Gotta say this video helped me understand virtual functions a lot more than anything else so far.
    Going to have to hunt down the other things that confuse me. I've been following a C++ tutorial app at work during breaks and such and these were stumbling blocks that undermined my whole understanding of polymorphism.

  • @JohannesBergerSiroky
    @JohannesBergerSiroky 8 месяцев назад +1

    In 2:10 an entity pointer is pointing to a memory area assigned to a player object. It will get converted this way: Entity *e = (class Entity*)p; Great video!

  • @jonathangerard745
    @jonathangerard745 3 года назад +5

    Virtual functions at first seemed harder than pointers for me... You've simplified it so elegantly... Thank you :)

  • @RossYlitalo
    @RossYlitalo 4 года назад +1

    Very nice explanation. Short and right to the point. It's easy to agree with your assessment that v-tables have such minimal cost that the inconvenience of not using them makes using them a no-brainer. Thank you very much!

  • @thomashaug5086
    @thomashaug5086 4 года назад +2

    Dude you are great at explaining these things. Probably won't ever see this comment but thank you. I don't write comments a lot but I am teaching myself c++ and I've watched several of your vids and they are awesome and extremely helpful. Thanks again!

  • @LunaFlahy
    @LunaFlahy 2 года назад +1

    1. Virtual function: declared in the base class, which enables the derived object to use its override function.
    2. Override: declared after the function in the derived class. not required, but avoid misspelling the function name or overriding the non-virtual function in the base class.
    3.V Table : stores the virtual function in the base class to dispatch, which cost space, int * pointer to the override function.
    4. in specific embedded systems, using v table might impact the performance .

    • @immalkah
      @immalkah 2 года назад +1

      Rewording content in summary form is actually a great way to learn and reinforce knowledge 👍🏽

  • @0xbitbybit
    @0xbitbybit Год назад

    Haha loving the "is he going to be in focus or not?" game I'm playing watching through these videos 😂 such an epic series though mate, thanks!

  • @systematicloop3215
    @systematicloop3215 7 лет назад +19

    I don't know if I particularly like the fact that the override keyword comes after the function signature. I come from C#, so it's strange to look at.

    • @vertigo6982
      @vertigo6982 6 лет назад +6

      You must unlearn what you have learned.

  • @ProtonPhoenix
    @ProtonPhoenix 3 года назад +2

    -> in c++ ~~~ An operator in C/C++ allows to access elements in Structures and Unions. It is with a pointer variable pointing to a structure or union. The operator is formed by using a minus sign, followed by the geater than symbol as shown below but bro we didn't reach union yet

  • @laureven
    @laureven 5 лет назад +49

    If I was new to this I would have struggled to understand. Your explanation is very good but it is impossible to pause the video to see all code to be able to imagine this scenario. It would be nice to have this simple code all on the screen and then You explaining it. In Your video, You jumping between screens and this create a lot of confusion for all newbies I imagine. Maybe a smaller font :) ..the point is If I explaining this to anybody I Print the example code on a single page and then explain, If I jump pages from declarations to the main function this is very confusing ...but this is just me ...Anyway I like Your videos Regardless :) Regards

    • @zaid4708
      @zaid4708 5 лет назад +6

      ikr its confusing where he keeps on jumping everywhere i cant keep up

    • @froycardenas
      @froycardenas 5 лет назад +3

      Certainly, this is not a topic for a newbie... virtual function is a complex feature of class heritance that I don't think there is an easy way to explain to people who have never coded anything in their life. This guy is obviously an expert and knows what he is talking about because he must have been programming for years.

    • @ashwinregi9215
      @ashwinregi9215 4 года назад +1

      That's true! I kept on pausing the screen to get it

  • @jackthehammer2245
    @jackthehammer2245 7 лет назад +3

    Thanks for your video. One thing I could add for virtual keyword is to add this keyword on destructor of the parent class to prevent memory leak when a derived class is deleted through the parent pointer.

  • @TheSunscratch
    @TheSunscratch 7 лет назад +46

    What is the difference between
    Player(const std::string& name):m_name(name) {}
    and
    Player(const std::string& name) {
    m_name = name;
    }
    Is it some kind of syntactic sugar?

    • @TheSunscratch
      @TheSunscratch 7 лет назад +2

      Lightslinger Deadeye many thanks for your explanation!

    • @TheCherno
      @TheCherno  7 лет назад +86

      There's no _real_ practical difference between the two, however there is a difference. Since m_Name is a class member which has the type std::string (which is stack-allocated), it will actually be instantiated twice in your second example (firstly with an empty string, and secondly copied from the name parameter), but only once in your first example (via the constructor's intiailiser). Definitely going to be a video on this in the future. :)

    • @TheSunscratch
      @TheSunscratch 7 лет назад +1

      TheChernoProject thanks :)

    • @BlackPhillip-sw8xf
      @BlackPhillip-sw8xf 7 лет назад +2

      +TheSunscratch Also you cannot use the first approach if the data member is static.

    • @matteocampo1732
      @matteocampo1732 7 лет назад +5

      Does the compiler (with -O2 or -O3 ) optimize it so that there is no difference eventually?

  • @Fidelity_Investments
    @Fidelity_Investments 2 года назад +7

    you kinda ran away at the beginning there. You've not gone over the Player(const std::string& name) : m)Name(name) {} syntax, nor the e->GetName() syntax. You kinda just left a lot of people in the dust there my guy.

  • @michaelkane1072
    @michaelkane1072 2 года назад

    It is the luckiest moment in this year that i found these series right after i started learning cpp

  • @Mikerandria
    @Mikerandria 4 года назад +1

    Thank you! You explained VTable so easily. I can continue my Reverse Engineering tutorials in peace now. Keep up the good work!

  • @Chillzn-yt
    @Chillzn-yt 3 года назад +1

    Employer in the interview: "Where did you study?"
    Me: "The Cherno University..."
    Employer in the interview: "Where is that located?"
    Me: "RUclips..."

  • @mytech6779
    @mytech6779 2 года назад

    In Bjarne's book he states the cost of a vtbl as two memory accesses plus the function call, exactly. The vtbl is just a collection of pointers to pointers.
    Two accesses is proportionally huge for some special cases and totally insignificant for others.

  • @haroldfinch360
    @haroldfinch360 6 лет назад +364

    So far your videos have been good. But this is the first one I do not like. You're using and refering way too much, you actually did not use at this point of the series. Initialationlits, the ->, randomly using a pointer with the keyword new as an object and so on. WAY too much new stuff that has not been covered yet.

    • @Redfrog1011
      @Redfrog1011 5 лет назад +23

      Absolutely agree

    • @explorerofworlds512
      @explorerofworlds512 4 года назад +10

      Yes. Agreed! Please reorganize the playlist. At least put this tutorial after the -> tutorial and the new keyword tutorial. And as far as I can tell you still haven't done a dedicated tutorial to polymorphism so why refer to it here.

    • @masondaub9201
      @masondaub9201 4 года назад +20

      @@explorerofworlds512 the -> is essentially just a shorthand for dereferencing a struct or class pointer and then trying to access a member.
      // declare a new pointer to a myClass object and then use new to allocate enough memory for it
      myClass* myclass = new myClass();
      myclass->some_func();
      // is equivalent to
      *(myclass).some_func();

    • @explorerofworlds512
      @explorerofworlds512 4 года назад +5

      @@masondaub9201 Yeah, i came back to it later. It makes a lot more sense after watching later tutorials. Like I said needs would be great to have the playlist rearranged a bit.

    • @nikitanovikoff2266
      @nikitanovikoff2266 4 года назад

      +

  • @PerchEagle
    @PerchEagle 5 лет назад

    Dude ! You are wonderful, you are smart not to explain unnecessary stuff. Explain the important things and other important related aspects ! wow ..

  • @yugantkadu8621
    @yugantkadu8621 4 года назад +2

    Please make a video on V Table and Memory allocation. I have been watching C++ playlist, your videos are very good to get concepts more clear.

  • @danielketcheson1965
    @danielketcheson1965 2 года назад +2

    This series
    Applies in 2022
    Meets the standards for my school's conventions (industry standards)
    Is more articulate and understandable than the "C++ For Dummies" series
    Has a loving/lovable character directing it
    I (with next to no rep or qualifications) award the Cherno with best C++'s best resource award
    I said it here
    Now I'm going to say it everywhere else.

  • @fireball111121
    @fireball111121 3 года назад

    Thank God for these videos. My professor is super chill, but he's so bad at explaining things. He reads the book at us and then explains things as though we already know it and moves way too fast and gets way too complicated.

  • @wayneray9489
    @wayneray9489 3 года назад +6

    This is really complicated for me a new learner.

  • @pascalladal8125
    @pascalladal8125 2 года назад

    Hey Cherno! Got to say great channel to learn c++, awesome channel to get used to the australian accent!! :)

  • @bartlomiejodachowski
    @bartlomiejodachowski 2 года назад +2

    1:10 why is m_Name, class variable, used after : and with () like a function ?
    is : part of labda" notation ? and () funcional" casting/asigment ?

  • @cap-advaith
    @cap-advaith 2 года назад +1

    player(const std:string& name):m_name(name){} // this is an example of initializer list

  • @salpelter
    @salpelter Год назад

    tysm! every topic you explain is so clear and simple

  • @rahulpillai1271
    @rahulpillai1271 Год назад +1

    6 years later and I am still waiting for your VTable Video Cherno. 😆 I love your series. Please link me to the vtable video if there is one.

  • @othmaneparadis1576
    @othmaneparadis1576 4 года назад +1

    guys this is the hardest in c++ so dont quit

    • @dwivedys
      @dwivedys 7 месяцев назад

      Thanks for that timely and apt reminder! You got this all of you!!

  • @rcookie5128
    @rcookie5128 7 лет назад

    Good stuff. Knew and used virtual functions already and funnilly enough I already learned this morning about the word "override" (also spoiler alert: final and volatile classes/member functions :O so much to learn!).

  • @aritzolea6554
    @aritzolea6554 7 лет назад +10

    A very basic question (coming from java).
    Why do you write Entity* e = new Entity()? Why do you add that pointer * ?

    • @TheCherno
      @TheCherno  7 лет назад +17

      Because the *new* keyword dynamically allocates memory and returns a pointer to the address of that allocated memory, hence why we need a pointer type. Check out my video on pointers if you haven't already, and I will definitely be making a video on memory allocation in the future.

    • @edino1981
      @edino1981 7 лет назад +4

      I will just add that in Java classes are by default reference types, while in C++ everything is value type, so if you need to refere to the same value, then you need to use pointers. So you can use same class definition as reference or value type. For example if you have new class Vector (position) , and you pass it to function as Vector (by value) or as Vector * ( as pointer only). If you embed Vector in Entity you can embed entire Vector or only a pointer to Vector.

  • @TheSim00n
    @TheSim00n 7 лет назад +10

    Awesome video as always Yan. I know for the general use of virtual functions this video is absolutely enough, but I would love to see an explanation of how early and late binding comes into play with these functions and the concept of a vtable. Thanks!

    • @TheCherno
      @TheCherno  7 лет назад +10

      Yes, that will be covered in the vtable video. Late binding doesn't _really_ exist in C++ since everything must be known at compile time, and the vtable essentially just allows dispatching to a number of preset values (that are contained in the table), not to _anything_ which would be the case with late binding.

    • @TheSim00n
      @TheSim00n 7 лет назад +2

      Right on. Thanks.

  • @Fallkhar
    @Fallkhar 7 месяцев назад

    Excellent, just what I needed.

  • @mockingbird3809
    @mockingbird3809 4 года назад +1

    Excellent explanation. Something I'm looking for. Thank you so much.

  • @higheredjohn8316
    @higheredjohn8316 7 лет назад

    Thanks for this - excellent refresher, and I learned a few new tidbits! Keep these coming.

  • @Grace-vg4hf
    @Grace-vg4hf 6 лет назад +1

    I'm working on an assignment and this is so helpful, thanks so much!

  • @GenericPhantom1
    @GenericPhantom1 2 года назад

    Virtual functions are basically backups for functions. So it tells the complier that if a function is overwritten then it knows that it originally meant.

  • @w3w3w3
    @w3w3w3 5 лет назад +7

    So many new concepts in this video, I wish you would just explain them quickly lol. All the other videos have been perfect. Thanks though.

  • @unmeinks5907
    @unmeinks5907 2 года назад

    this is virtually the best tutorial on youtube (:

  • @Dagrond
    @Dagrond 2 года назад +3

    I was wondering why you used the x->object style instead of x.object but it turns out that x.object won't use a vTable. Baby steps for me I guess.

  • @N_Sgames
    @N_Sgames 2 года назад +2

    I'm currently following your series and everything went pretty well, but when I got to this video, I didn't understand a thing. I have never learned about strings and stuff. Am I doing somehting wrong?

    • @zorex324
      @zorex324 Год назад +2

      Absolutely not he should have covered strings earlier in this series (according to me...)

  • @NGh_teh
    @NGh_teh 2 года назад +4

    Hey Cherno. Thanks for the videos first. Can you explain the syntax you used in the player constructor? what is this specifically: m_name(name){ }. I know it sets the name to variable m_name but I have never seen this syntax before. Why you didn't do it in the body and the body is just empty? Can anyone explain to me? Second question. Sometimes in the formal parameters, you expect a pointer but in the actual parameters, you pass a normal data type like a string literal. Also in the body function where you are expecting a pointer, you just use that variable without dereferencing. I am confused by this. Can you help me with that?

    • @enes5345
      @enes5345 2 года назад +6

      hey I hope you found answers your questions but this maybe helpful for someone else , for the first question:
      In c++ there is a way to initailize a variable with { } without using = operator , so for example int x{0} , y {10} (you basically did x=0, y=10;) and also you can use this way of initalization for constructors in this case ,
      Player(const std::string& name) :m_Name{name}{ } basically initalize m_Name to the value of name it is actually the same thing with
      Player(const std::string& name) { m_Name = name; }, depends on your style of coding
      for the second quesiton I think you mean this parameter in the Player constructor , (const std::string& name ) so here & says it is a referance to the variable not pointer , it is widely used for parameters to strings in order not to create a temporary string value and copying its value to it like
      void getName( string name) {m_Name = name; } because here you basically created a name variable and you passed a value to it like "Cherno" and you copy it to the m_Name, this means an extra garbage spaces right but if you use & then there wont be any name value created, so directly "Cherno" or , whatever you pass , it will be directly assigned to m_Name,
      I hope its clear and you can watch reference video or see more examples on it :)

    • @maolin7866
      @maolin7866 Год назад +1

      @@enes5345 thank you!

    • @enes5345
      @enes5345 Год назад +1

      @@maolin7866 you're welcome and also I am sorry I have learnt recently something new that I didn't know that in c++ initializing variables using initializer list( intiliazing variables after : ) is different than to initialize variables in the constructers body , when you initialize variables using initializer list what c++ do is it directly creates and initializes variables in the memory with the values that you have passed but doing this in the body of the constructers, c++ creates those variables in the memory and than assign them those values, this doesn't make much difference with intgrrs doubles or so but if you pass any object to the constructers like in copy constructers than using initializer list makes difference its faster as far as I know ( If you guys know sth diff pls tell us ) ,and one more thing initilazing vatiables using ( ) , and {} also different even in normal initialization like
      int a{}; different than int a(); again this might not make alot differencr for the int like variables it makes for objects creation , do in this way
      Point(string& name)
      : m_Name {name}
      {
      //Body
      }
      Thanks for your comment so that I could find a way to correct myself 😅🤗

    • @vickyzz4436
      @vickyzz4436 Год назад +1

      @@enes5345 Thank you for your explanation!

  • @mohamedabdul633
    @mohamedabdul633 4 года назад

    After surfing the internet for more than 10 minutes, and this tutorial was much more helpful.

  • @teena-tz7lr
    @teena-tz7lr 9 месяцев назад +1

    my question is at 2:00, why would u ever make an entity pointer when u know ur wanting to refer to to the player class.. seems more logical to just make a player pointer and then point to the instance of player to bypass any need for virtual functions at all.. i dont get why people are writing code like this its almost like they're purposely trying to make it confusing for no real good reason

    • @JohannesBergerSiroky
      @JohannesBergerSiroky 8 месяцев назад

      At first it can be very confusing if you don't know what's going on. Polymorphism is meant to be a convenient feature but can confuse many people. Struct pointer conversion is used sometimes in C and object pointer conversion here before polymorphism is probably used much more in C++. C++ uses type checking so the converted base class in the derived class' memory area has it's own functions that is used if virtual tables are not used. We have for example Entity *e = p;. Before, in g++ I could also type Entity *e = (class Entity*)p;. So here an instance of Entity is in p's memory area converted into Entity and p's functions is used if there is a virtual table. Otherwise Entity's functions are used.

    • @teena-tz7lr
      @teena-tz7lr 8 месяцев назад

      @@JohannesBergerSiroky tyvm

    • @JohannesBergerSiroky
      @JohannesBergerSiroky 8 месяцев назад +1

      @@teena-tz7lr You're welcome.

  • @TurtlesWithAutism
    @TurtlesWithAutism 4 года назад +1

    Okay Cherno... we get it... we are dumb. You happy now?
    Guess I'll just have to watch more of your videos to understand these unexplained concepts, which I was going to anyways because you're the best teacher ever.
    :D

  • @oleholgerson3416
    @oleholgerson3416 6 лет назад

    good videos, keep it up. so glad you dropped the backgroundmusic

  • @handlethissonny
    @handlethissonny Месяц назад +1

    DUDE UR VIDEOS R FUCKING AWESOMETYSM

  • @choosyguytest719
    @choosyguytest719 5 лет назад +39

    I dont get it... hard to understand at this point.

    • @loveboat
      @loveboat 5 лет назад +13

      These videos started out so exceptionally great but it seems he has grown weary of this subject now, rushing through them and using unexplained code all the time.

    • @vertigo6982
      @vertigo6982 5 лет назад +3

      Go review the video on Inheritance.. That should help you understand it better.

    • @woofelator
      @woofelator 5 лет назад +2

      @@loveboat wat

    • @deletevil
      @deletevil 4 года назад +6

      There is Zero problem with this video. If you don't get it then you haven't actually practiced inheritance enough to learn why we needed the virtual functions in the first place. Just watching videos will never get you anywhere in programming. You will have to actually write the code, test it with all possible conditions you can think of, try to do illegal stuff and then understand why it is not working, is the only way you can truly learn any topic.

    • @jerfersonmatos28
      @jerfersonmatos28 4 года назад +1

      @@deletevil I think he is not refering to virtual functions. Cherno introduced many other subjects in this video without explaining them, but all these are explained in future videos, so the only thing to take out of this video is the type "Virtual" subject

  • @RenanHiramatsu
    @RenanHiramatsu 6 лет назад +10

    Can someone explain me why he put a symbol & in front of string at 1:15
    And also why there is a : before the m_Name(name) {}
    Actually if someone could explain to me the lines 15 and 16 of the code would be easier.
    Player(const std::string& name) [I know that he creates a variable type string named name, but why &?]
    : m_Name(name) {}

    • @rupamroy3931
      @rupamroy3931 6 лет назад +1

      Renan H. The & refers to a variable passed by reference

    • @okmanek69
      @okmanek69 6 лет назад +4

      Thanks to & sign copy of this string will not be created when invoking this method. Code gets little bit more optimised.

    • @smolboii1183
      @smolboii1183 6 лет назад +7

      as the above have mentioned, the & after string means that rather than a copy of the string being passed to the function, the string itself will be passed, so anything done to that string will be done to the original string.
      the : before m_Name(name) {} indicates that an initialisation list will follow. an initialisation list is syntactic sugar; it replaces having to say m_Name = name; and so on for every member variable you wish to initialise. i also think it slightly boosts performance as local copies of the variables aren't created or something, although i'm not sure, but regardless the main reason you use it is to save time and improve readability.

    • @RenanHiramatsu
      @RenanHiramatsu 6 лет назад

      Thank you for clearing my doubts.

    • @bluehornet6752
      @bluehornet6752 6 лет назад +5

      Really, it's about performance.
      Let's say you were passing a 100-character string to a method. If it was passed-by-value, then you'd literally have to pass all 100 characters (bytes) to the method. But if it was passed-by-reference, then you'd only be passing a pointer to the string. So that's like 4 bytes on a 32-bit system.
      Keep in mind also that passing something into a method by reference allows that something to be modified in the called method where it got passed. So that's what you often see the "const" modifier used as well: You get the performance benefit of pass-by-reference, with the safety of "const."

  • @nunofigueira8691
    @nunofigueira8691 2 года назад

    Its was a very good and technical explanation, thank you.

  • @notremonde1652
    @notremonde1652 5 лет назад

    You a life saver. keep up the good work!

  • @uwu8750
    @uwu8750 7 лет назад

    Hey. Thank you so much! Had been waiting for this :)

  • @willd4686
    @willd4686 5 лет назад

    Your videos are amazing tools for learning this stuff.

  • @greg6094
    @greg6094 7 лет назад

    Cherno, you are an absolute legend!

  • @tsvetomirdenchev1440
    @tsvetomirdenchev1440 6 лет назад +2

    TheCherno, thank you for your great tutorials! Are you planning on making a tutorial on generic programming and C++ templates?

  • @VortexInfoTech-gw8hp
    @VortexInfoTech-gw8hp Год назад +1

    Why do you use pointers to those classes when creating instance of them ?

    • @JohannesBergerSiroky
      @JohannesBergerSiroky 8 месяцев назад

      I think one reason for that is that he must use pointers for using pointer conversion so that polymorphism will work later. Entity *e = (class Entity*)p;. It will go into p's memory area converted into the base class Entity.

  • @afrikamatshiye735
    @afrikamatshiye735 6 лет назад +10

    Wait wait wait... Why did I just understand virtual functions in one video. Dude you're good. Thanks man.

    • @karmaindustrie
      @karmaindustrie 6 лет назад +3

      This is the C++ apocalypse. Probably one positive side effect of Chernobyl.

  • @mahdishirazi5785
    @mahdishirazi5785 3 года назад +1

    is it even possible not to use virtual functions, specially in the Abstraction concept in OOP in which it's used primarily??

  • @Metachief_X
    @Metachief_X 4 года назад

    Super easy explanation. Many thanks mate

  • @jairoacosta8940
    @jairoacosta8940 5 лет назад

    thank you, i always come back to reference your videos.

  • @SR-oy5ou
    @SR-oy5ou 3 года назад

    you just summarized my 3 hours lecture in 5 minutes

  • @per-axelskogsberg3861
    @per-axelskogsberg3861 3 года назад

    This was perfect! Thank you 💕

  • @sameeranjoshi3819
    @sameeranjoshi3819 3 года назад +2

    @The Cherno when you say some people don't prefer virtual functions, what's the other option in that case?
    Is it CRTP ? Do you have a video on what to use if no virtual function?

  • @volts-kr4bu
    @volts-kr4bu 6 лет назад +6

    Hey Cherno...
    I am a beginner and I can't understand your complicated code...
    It is very difficult as u put lot of new stuffs in your code and u reach directly to the complicated level( acc. to me).
    What should I do?????

    • @piechulla1966
      @piechulla1966 5 лет назад

      There is no Nuremberg Funnel. Use textbooks. Play around with code. These videos just can give you deeper insights.

  • @shockwave1789
    @shockwave1789 4 года назад +68

    After watching this I realised Java is so easy compared to cpp.

    • @jscorpio1987
      @jscorpio1987 4 года назад +24

      On the flip side, the ease of Java comes at the expense of the level of control and optimization that C++ gives you. I started out with Java and now, after getting used to C++, Java just feels so limited.

    • @shockwave1789
      @shockwave1789 4 года назад +1

      @@jscorpio1987 Java's strength is in enterprise application ,it's toolset and frameworks are perfect for that . Yes it doesn't have much control over small low level optimisation due to jvm ,but platform independence compensates it perfectly .

    • @ezshroom
      @ezshroom 4 года назад

      @@jscorpio1987 I also started with Java. And, even now, I still prefer Java over C++ but I see the strengths of it too. For example, anything related to graphics in Java to me seems like it hasn't really been thought about too much. Mean, games built with it are (usually) a lot slower and even basic interfaces are difficult to make. With C++, there are many more libraries built to help with this. While these libraries are often ported to Java, it just doesn't feel complete.

    • @aryanparekh9314
      @aryanparekh9314 4 года назад +2

      After looking at the sky I realized it's blue

    • @smileynetsmileynet7922
      @smileynetsmileynet7922 4 года назад +4

      Me using java: Why isn't this applet working? It worked last time I used java!
      About 1.5 years ago...

  • @youssofprogrammer2389
    @youssofprogrammer2389 2 года назад +1

    Actually, I love this Tutorial very much and this is the Third time I repeated this video
    but I noticed that this Play list is not in the correct order,
    What Should I do it a disaster for me because I always depend on this tutorial
    and no more any tutorial else
    Plzzzzzzz Help!!!!!!!!!!!!!!!!!!!!!!!!

  • @boongbaang1124
    @boongbaang1124 3 года назад

    1:09 why did he make the constructor take in a reference rather than just the string? I know the definition of reference, but what's the benefit here that the reference brings?

  • @lesptitsoiseaux
    @lesptitsoiseaux 4 года назад +2

    I can't say how useful your series has been. My son is twelve and is into robotics and programming and switching from python to C++. He loves your series and I'm playing catchup to help him though I'm the one lagging behind. Thank you, and let me know, if you read this, if you ever considered doing something about OpenCV or anything machine learning? :-D

  • @mateusz-czajkowski
    @mateusz-czajkowski 4 года назад

    2:39 that resignation in his voice lmao

  • @jasonsui9029
    @jasonsui9029 3 года назад

    what a wonderful tutorial! Love it!

  • @song5030
    @song5030 7 лет назад +7

    Hey Cherno! Are these tutorials going to be by the C++ 14 and up standart? I mean like will these tutorials be of modern C++?

    • @somedude4122
      @somedude4122 7 лет назад

      Yup. Many of these will work on pre C++11, but most are C++24, especially the later videos, which are strictly C++14 and up

  • @AngelTaylorgang809
    @AngelTaylorgang809 4 года назад

    awesome video man

  • @PflanzenChirurg
    @PflanzenChirurg 7 лет назад +3

    Love u dude

  • @34sisantachhatoi34
    @34sisantachhatoi34 6 месяцев назад

    Concise... Like always😊

  • @exoticcoder5365
    @exoticcoder5365 3 года назад +1

    Super helpful gosh

  • @vaiterius
    @vaiterius 2 года назад

    thanks Cherno

  • @eyesight2073
    @eyesight2073 3 года назад

    c++ community:
    language gives us this feature😘. but it comes with 'cost' 🥺
    javascript community:
    we don't care about cost. we are rich 🥳

  • @PereAmengualGomila
    @PereAmengualGomila 3 года назад

    Has the initialization list in the constructor of Player been explained before? I've been scratching my head for a few minutes until I googled it out...

  • @shirinkoul
    @shirinkoul 3 года назад +1

    I enjoyed the video :)

  • @KingUnity22
    @KingUnity22 5 лет назад

    So let me get this right... virtual functions are basically a way to allow a derived class to override a method from its base class so that everything stays nice and organized? So you can declare a function as virtual so that base classes won't use that function when calling an instance of their own function?

    • @KishoreG2396
      @KishoreG2396 5 лет назад

      Well no. It depends on the instance. A base class has no knowledge of what its derived classes are, so it cannot call a derived class method beccause it doesn't know it. If you have a virtual method, and a base class instance, then it will call the original base class instance. If you have a derived class and you use its instance, it will use the overrided virtual function in the base class. If you have a base pointer which actually points to a derived instance (polymorphism), it can only access non-virtual base class methods and the overrided derived class methods.

  • @thunder852za
    @thunder852za 4 года назад

    dynamic polymorphism is factor 8 as opposed to static polymorphism. Use it at a high level and you won't notice. Make 100000 calls and you notice.

  • @ankitjain3461
    @ankitjain3461 3 года назад +6

    More than 3 years now, still waiting for VTABLE video 😆

  • @altSt0rm
    @altSt0rm 3 года назад +2

    Genius level teaching.. 10/10

  • @cawlex
    @cawlex 6 лет назад

    1:23 why did you make the Entity object a pointer, can't it work without that asterisk?

  • @Joshua-gu5nj
    @Joshua-gu5nj 6 лет назад +4

    Your hair reminds me of that scene in There's Something About Mary. You know which one.