# Is multiple dispatch the same as function overloading?

**URL:** https://discourse.julialang.org/t/is-multiple-dispatch-the-same-as-function-overloading/4145
**Category:** New to Julia
**Tags:** multidispatch
**Created:** [June 7, 2017, 7:56pm UTC](https://discourse.julialang.org/t/is-multiple-dispatch-the-same-as-function-overloading/4145 "2017-06-07T19:56:40Z")
**Posts on this page:** 1
**Showing post:** 11

<div class="post-metadata">

### Author: ![ti-s](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti-s/32/25619_2.png) [@ti-s](https://discourse.julialang.org/u/ti-s)
#### Post date: [June 9, 2017, 5:14pm UTC](https://discourse.julialang.org/t/is-multiple-dispatch-the-same-as-function-overloading/4145/11 "2017-06-09T17:14:04Z")

</div>

Also in Julia there is static and dynamic dispatch. Static dispatch happens when inference can figure out the concrete type. For example (with the definitions from my previous post):

```julia
function static_dispatch()
    c1 = C1()
    c2 = C2()
    foo(c1, c1)
    foo(c1, c2)
    foo(c2, c1)
    foo(c2, c2)
    nothing
end

@code_warntype static_dispatch()

```

prints

```julia
Variables:
  #self#::#static_dispatch
  c1::C1
  c2::C2

Body:
  begin # line 23: # line 24:
      $(QuoteNode(3)) # line 25:
      $(QuoteNode(2)) # line 26:
      $(QuoteNode(1)) # line 27:
      $(QuoteNode(1)) # line 28:
      return Main.nothing
  end::Void

```

(In this case, the method invocations have been replaced with their constant return values, so this is not the best example).

Static dispatch is the same in C++:

```julia
    C1 c1 = C1();
    C2 c2 = C2();
    std::cout << c1.foo(&c1) << std::endl;
    std::cout << c1.foo(&c2) << std::endl;
    std::cout << c2.foo(&c1) << std::endl;
    std::cout << c2.foo(&c2) << std::endl;

```

which prints the same values

```julia
3
2
1
1

```

Thus, multiple dispatch in Julia is only special at runtime, i.e., when the type cannot be statically inferred (there might be more subtle differences in static dispatch, too).

---

_[View the full topic](https://discourse.julialang.org/t/is-multiple-dispatch-the-same-as-function-overloading/4145)._
