Created
April 15, 2018 02:26
-
-
Save moutend/4221a6c730b75b3c3b4fd660169fff47 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <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