# Constructors - cannot convert from type to object

**URL:** https://discourse.julialang.org/t/constructors-cannot-convert-from-type-to-object/6536
**Category:** New to Julia
**Created:** [October 18, 2017, 9:39pm UTC](https://discourse.julialang.org/t/constructors-cannot-convert-from-type-to-object/6536 "2017-10-18T21:39:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)
#### Post date: [October 18, 2017, 9:39pm UTC](https://discourse.julialang.org/t/constructors-cannot-convert-from-type-to-object/6536/1 "2017-10-18T21:39:09Z")

</div>

I’m trying to create a tree class using Dicts. The base struct is:

```
mutable struct MyNode
    name::String
    information::Tuple
    children::Dict{String, MyNode}
end

```

I have a constructor:

```
MyNode(name::String) = MyNode(name, (), Dict{String, MyNode}())

```

If I try to construct a MyNode from the REPL like so:

```
> tree1 = MyNode("root", (), Dict{String, MyNode}())

```

it works. But if I try to use the constructor I get an error:

```
> tree = MyNode("root")
ERROR: MethodError: Cannot `convert` an object of type Type{Dict{String,MyNode}} to an object of type Dict{String,MyNode}
This may have arisen from a call to the constructor Dict{String,MyNode}(...),
since type constructors fall back to convert methods.

```

What am I doing wrong?

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [October 18, 2017, 9:41pm UTC](https://discourse.julialang.org/t/constructors-cannot-convert-from-type-to-object/6536/2 "2017-10-18T21:41:50Z")

</div>

Your code works perfectly here (BTW, thanks for the reproducible test case!). Looking at the error message, I suspect you forgot `()` after `Dict{String, MyNode}` at some point during your testing.

---

<div class="post-metadata">

### Author: ![GlenHenshaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glenhenshaw/32/5269_2.png) [@GlenHenshaw](https://discourse.julialang.org/u/GlenHenshaw)
#### Post date: [October 18, 2017, 9:49pm UTC](https://discourse.julialang.org/t/constructors-cannot-convert-from-type-to-object/6536/4 "2017-10-18T21:49:42Z")

</div>

Errr. So quitting the REPL and restarting, and you are correct. It works. I did, in my first iteration, forget the trailing parens. But why didn’t it get loaded over when I reloaded the module file?
