Virtual Functions in C++

40
5



Twitter ►
Instagram ►
Patreon ►
Slack ►

Series Playlist ►

BEST laptop for programming! ►
My FAVOURITE keyboard for programming! ►
FAVOURITE monitors for programming! ►

MAIN Camera ►
MAIN Lens ►
Second Camera ►
Microphone ►

Nguồn: https://chototdayroi.com

Xem thêm bài viết khác: https://chototdayroi.com/cong-nghe/

40 COMMENTS

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

  2. Player (const std::String& name) : m_Name (name) { }
    why is the :m_Name there?
    should it now be the in "{ }"

    Also why is no return used?

  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!

  4. 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.

  5. 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.

  6. until this video, ur videos is very good. But in this video, there is so much things to uncovered and not explained. hard to cover.

  7. 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!

  8. Player* p = new Player();
    Entity* entity = p;
    so now entity is a pointer pointing at p(Player class)
    so when calling
    entity->GetName();
    it should be equal to
    p->GetName();
    which means the GetName() function inside the Player class is supposed to invoked
    am i not correct
    why must the virtual keyword be added to make it possible to invoke the GetName() in Player class?

  9. Just curious, in another video of yours you state that most of the time you would want to use the stack. Why do you use the new keyword instead of doing something like "Entity e;" ?

  10. Is there any way in c++ to make a functional that takes some arguments in a class but takes other arguments in inherited class.

    For example: I have a class A and a class b inherited from class A. Class a has a function called Print(int a) and class B will have the same function Print with different variables like Print(char* b)

  11. 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.
    😀

  12. If you are looking for the whole code, here it is:
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    using namespace std;
    struct Animal
    {
      public:
      virtual string GetName() { return "Animal"; }
    };
    struct Dog : public Animal
    {
    private:
      string m_Name;
    public:
      Dog(const string& name): m_Name(name) {}
      string GetName() override { return m_Name; }
    };
    void PrintName(Animal* animal)
    {
      cout << animal->GetName() << endl;
    }
    int main()
    {
      Animal* a = new Animal();
      PrintName(a);
      Dog* d = new Dog("dog");
      PrintName(d);
      cin.get();
      return 0;
    }

  13. If you're confused by this video and the next video… come back to it after watching more of his videos in the playlist. They are a bit out of order.

  14. This wouldn't have worked if you did:
    Entity e;
    Player p;

    right? I tried it and I had to use a pointer to each on the heap.

  15. 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?

LEAVE A REPLY

Please enter your comment!
Please enter your name here