Created
December 24, 2016 11:33
-
-
Save DarkMio/3f1e1a38b3dbb672747bd729e5a7582b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Drawbale { | |
public: | |
virtual void draw() const = 0; | |
}; | |
class A : Drawable { | |
virtual void draw() const { /*...*/ } | |
}; | |
class B : Drawable { | |
virtual void draw() const { /*...*/ } | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Classes.cpp" | |
#include <vector> | |
void main() { | |
// Example Page 38 | |
A a; | |
B b; | |
std::vector<const Drawable&> v; | |
v.push_back(a); | |
v.push_back(b); | |
for(auto d : v) { | |
d.draw(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Classes.cpp" | |
#include <vector> | |
#include <memory> | |
void main() { | |
// smart pointers or raw pointers, idc. | |
auto a = std::make_unique<A>(); | |
auto b = std::make_unique<B>(); | |
std::vector<std::unique_ptr<Drawable>> v; | |
v.push_back(a); | |
v.push_back(b); | |
for(auto d : v) { | |
d->draw(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment