Skip to content

Instantly share code, notes, and snippets.

@moutend
Created April 15, 2018 02:26
Show Gist options
  • Save moutend/4221a6c730b75b3c3b4fd660169fff47 to your computer and use it in GitHub Desktop.
Save moutend/4221a6c730b75b3c3b4fd660169fff47 to your computer and use it in GitHub Desktop.
#include <iostream>
class Clock {
protected:
int time;
public:
Clock() { time = 0; }
int GetTime() { return time; }
void Tick() {
time += 1;
if (time == 60) {
Action();
}
}
virtual void Action() { std::cout << "foo" << std::endl; }
};
class LaughClock : public Clock {
public:
virtual void Action() { std::cout << "bar" << std::endl; }
};
int main() {
Clock c;
c.Action();
LaughClock l;
l.Action(); // baby オブジェクトのクラスは LaughClock であるため、
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment