Run Code
|
Code Wall
|
Users
|
Misc
|
Feedback
|
About
|
Login
|
Theme
|
Privacy
Simple enemy polimorphism
#include <iostream> #include <vector> struct Enemy { std::string Name="---"; int HP=0; void Draw() { std::cout<<Name<<" HP: "<<'\n'; } }; struct FireGolem : Enemy { FireGolem() { Name="Fire golem"; HP=100; } }; struct Wolf : Enemy { Wolf() { Name="Wolf"; HP=30; } }; struct Dragon : Enemy { Dragon() { Name="Dragon"; HP=500; } }; int main() { std::vector<Enemy*> Vec; Vec.push_back(new Wolf); Vec.push_back(new FireGolem); Vec.push_back(new Dragon); for(auto i:Vec) { i->Draw(); } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Undefined behavior
Project Euler - 113
g++ -Wall *.cpp -o aco; ./aco.
Two-phase sample with GCC
creating triangle using nested loop
gal2
compute power to a number manually, and by using function.
srednie
protected
funpointer
Please log in to post a comment.