Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- struct Mom
- {
- virtual void play_strategy() const
- {
- std::cout << "Watching television" << std::endl;
- }
- virtual ~Mom() { }
- };
- struct FemaleChild: Mom
- {
- virtual void play_strategy() const override
- {
- std::cout << "Playing with dolls" << std::endl;
- }
- };
- struct MaleChild: Mom
- {
- virtual void play_strategy() const override
- {
- std::cout << "Kicking football around" << std::endl;
- }
- };
- struct UnrelatedWitchMom
- {
- void play_strategy() const
- {
- std::cout << "Killing innocent children" << std::endl;
- }
- };
- template <typename T,
- typename = typename std::enable_if<std::is_base_of<Mom, T>::value>::type>
- void play_type(T *obj)
- {
- obj->play_strategy();
- }
- int main()
- {
- Mom my_mom {};
- Mom *you = new FemaleChild{}, *me = new MaleChild{};
- play_type( &my_mom );
- play_type( you );
- play_type( me );
- UnrelatedWitchMom mom_ah {};
- play_type( &mom_ah );
- delete you;
- delete me;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement