Question: Going through codeacademy for python, one task was to write a function that would take a string and have a certain word censored out with asterisks, and then return the string. I tried it one way and it didn't work but I then tried it another way and it did. I just was curious as to why.

The one that didn't work:

```
def censor(text, word):
    split_string = text.split()
    replace_string = "*" * len(word)
    for i in split_string:
        if i == word:
            i = replace_string 
    return " ".join(split_string)

```

The one that did work: 

```
def censor(text, word):
    split_string = text.split()
    replace_string = "*" * len(word)
    for i in range(0, len(split_string)):
        if split_string[i] == word:
            split_string[i] = replace_string
    return " ".join(split_string)

```

Answer: 
The title of your question: "static dispatch" - unfortunately your problem requires finding out the type at runtime... You want to identify the actual type from some base class pointers. This will work only at runtime.

Using `dynamic_cast` is a hack, the usage of dynamic\_cast along usually means bad OO design. BTW, my bet would be that using `dynamic_cast` (`dynamic_cast` can be pretty slow!) and then a static function call is slower than simply making `f()` virtual and putting it to your base class and calling it that way.

Of course your case is a bit more special, you want to perform something else for all 8 cases but this is a piece of dirt work you won't be able to solve elegantly with brief code in C++ in my opinion. It is possible to forge a solution that is less error prone/easy to extend or one that is better in performance but none of them will be brief and/or elegant. Your current `doStuff()` implementation is rather a less error prone "bulletproof" solution, another one ugly solution has just came to my mind that would have good performance even for a lot of derived classes and class combinations (own type enum with own gettype + switch) but that is ugly as hell.

Summing it up: This problem has no nice solution in C++. You have to rethink your design or you have to live with ugly code when it comes to problems that can not be solved elegantly in C++: for example in case of serialization you often find ugly code like this...
This is a classical multiple-dispatch problem. It's very well developed in the literature. One of the solutions is the Visitor pattern (you need to apply it twice as you have 3 arguments to dispatch on). Another one is a `map<tuple<type_info, type_info, type_info>, StuffDoer>` (the latter class should have a virtual `doStuff` method and do a dynamic\_cast to all arguments inside).