C++/Game Tutorial 34: Pure Virtual Functions and Abstract Classes!

preview_player
Показать описание
In this episode we learn about pure virtual functions and abstract classes! An abstract class is just a class with one or more pure virtual functions.

Рекомендации по теме
Комментарии
Автор

this explanation really hit a home run. now i get it.

spicytuna
Автор

Just to let you guys know that you can loop  a for()  through monsters.push_back(new Goblin) to create as many goblins you want, if you have a name function you can call it like this, monsters[i]->name();, just like a pointer array!, but don't forget to clear the heap memory when you are done!! monsters.clear();

toastplayer
Автор

nice example of virtual functions in a game dev context.

Just a reminder, though, people watching this may see that "enemies.push_back(new Vampire);" and not realize they also need to manually delete all those raw pointers. It's good practice to always delete heap allocated objects, even if it's just before main returns. I would use " when the vector has ownership of the objects.

TheRealJman
Автор

Awesome! So any pure virtual function will make that class an abstract class?

gavinpierce
Автор

Hey ben! ¿are you making a voxel game in c++? I say it cause I saw some things in your videos that seem to be a game, so if you are doing it, please make a tutorial please :3

WitnessOfHorrors
Автор

Why would you even have a pure virtual function attack() in the Enemy class if you can't even use it?

mistermuffin