# Type, Structure

**URL:** <https://discourse.julialang.org/t/type-structure/30290>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 25, 2019, 6:51am UTC](https://discourse.julialang.org/t/type-structure/30290 "2019-10-25T06:51:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anil\_Mathews](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@Anil\_Mathews](https://discourse.julialang.org/u/Anil_Mathews)\
**Post date:** [October 25, 2019, 6:51am UTC](https://discourse.julialang.org/t/type-structure/30290/1 "2019-10-25T06:51:48Z")

</div>

I want to create Structure to store my details

```julia
struct MyStruct

        name:: String
        age ::int 
        Father_Name:: String
end  

data= Array{MyStruct,1}("anil",22,"Mathew) 

```

Then, I want to use MyStruct Type in an Array

Unfortunately, it’s wrong, how to code

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 25, 2019, 6:58am UTC](https://discourse.julialang.org/t/type-structure/30290/2 "2019-10-25T06:58:49Z")

</div>

Your code has several syntax errors (`Int`, closing quote in `"Mathew"`), but apart from that, you still have to use the explicit constructor to create an instance of `MyStruct`, which you can put in a vector. Eg

```julia
struct MyStruct
    name::String
    age::Int 
    Father_Name::String
end  

data = [MyStruct("anil", 22, "Mathew")]

```

see the manual:  
[https://docs.julialang.org/en/v1/manual/types/#Composite-Types-1](https://docs.julialang.org/en/v1/manual/types/#Composite-Types-1)

---

<div class="post-metadata">

**Author:** ![Anil\_Mathews](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@Anil\_Mathews](https://discourse.julialang.org/u/Anil_Mathews)\
**Post date:** [October 25, 2019, 2:05pm UTC](https://discourse.julialang.org/t/type-structure/30290/3 "2019-10-25T14:05:44Z")

</div>

Thank you for your answer.  
First of all,I am not programmer,I believe, i could not make that Array, because, julia is multi dispatching, when i create array, julia will check function with type argument and since mystructure is not pre defined, julia will not match the function. Am i right?  
Then, i have read the topic, unfortunately, i didnt understand anything. Could you please explain with Examples.  
Moreover, “not all types can have a respective object  
(instances of that type)” .Please explain this also with examples.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 26, 2019, 6:16am UTC](https://discourse.julialang.org/t/type-structure/30290/4 "2019-10-26T06:16:58Z")

</div>

> [@Anil\_Mathews](#):
>
> i could not make that Array, because, julia is multi dispatching, when i create array, julia will check function with type argument and since mystructure is not pre defined, julia will not match the function. Am i right?

I don’t think so. I am not sure I understand what you are saying here though.

> [@Anil\_Mathews](#):
>
> Then, i have read the topic, unfortunately, i didnt understand anything. Could you please explain with Examples.

If you want to program (any language, not specifically Julia), I think you should invest the time in learning the basics. I still think that working through the manual from the beginning is the best option, but there are some books here:

> **[Get started with Julia](https://julialang.org/learning/)**
>
> The official website for the Julia Language. Julia is a language that is fast, dynamic, easy to use, and open source. Click here to learn more.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 26, 2019, 8:23am UTC](https://discourse.julialang.org/t/type-structure/30290/5 "2019-10-26T08:23:03Z")

</div>

to fix based on your code, the minimal modification is:

```julia
julia> Array{MyStruct,1}([MyStruct("great",2,"nice")])
1-element Array{MyStruct,1}:
 MyStruct("great", 2, "nice")

```

The reason is that the `Array{T,N}` constructor wants the argument to be an array with `eltype` being `T`, I understand this is not the easiest code to write, so I wonder if there’s better way.

But, I noticed you can ‘hack’ the `Base.convert` a little:

```julia
julia> Base.convert(MyStruct, x::AbstractArray) = MyStruct(x...)

julia> Array{MyStruct,1}([["great",2,"nice"], ["hmm", 3, "hacky"]])
2-element Array{MyStruct,1}:
 MyStruct("great", 2, "nice")
 MyStruct("hmm", 3, "hacky")

```

which, at this point you might as well just write:

```julia
MyStruct(x::Tuple) = new(x...) #inner constructor inside `struct`

julia> MyStruct.([("great",2,"nice"), ("hmm", 3, "hacky")])
2-element Array{MyStruct,1}:
 MyStruct("great", 2, "nice")
 MyStruct("hmm", 3, "hacky")

```
