Hacker News new | ask | show | jobs
by rgoulter 2664 days ago
The example code the author comes up with: https://github.com/dpugson/examples/blob/master/chpt1_the_vi...

Which implements the pseudocode: https://cppcrypt.tumblr.com/post/168134402897

    main {
        thingies = [ purpleThingy, littleThingy ]
        interactions = [ commentOn, cherish ]

        for (interaction in interactions)
          for (thing in thingies)
             interaction.interact(thing)
    }
The author does mention things like "function pointers can be used in simple cases" and "std::variant would avoid the need to overload the method". But the main reason for having the C++ code the way it is is because "you can't dispatch to overloaded methods at runtime". https://cppcrypt.tumblr.com/post/169439207562 ff.