# Inner constructor error

**URL:** <https://discourse.julialang.org/t/inner-constructor-error/91811>\
**Category:** New to Julia\
**Created:** [December 18, 2022, 12:57pm UTC](https://discourse.julialang.org/t/inner-constructor-error/91811 "2022-12-18T12:57:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bananthahally](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bananthahally/32/222983_2.png) [@Bananthahally](https://discourse.julialang.org/u/Bananthahally)\
**Post date:** [December 18, 2022, 12:57pm UTC](https://discourse.julialang.org/t/inner-constructor-error/91811/1 "2022-12-18T12:57:30Z")

</div>

Hi

I’m trying to create a test inner constructor to get scalar fields from a vector input. I find the following code works **if I don’t** provide the statement “new()” at the end, but in that case the instantiated object only has the scalar value of c rather than all of a, b and c.

```julia
mutable struct TestStruct{T <: Real}
    a :: T
    b :: T
    c :: T

    function TestStruct(V :: Vector{T}) where T <: Real
        a :: T = V[1]
        b :: T = V[2]
        c :: T = V[3]
        new(a,b,c)
    end
end

```

The error I get on running the above is

```julia
ERROR: syntax: too few type parameters specified in "new{...}" around /Users/vijay/Documents/JULIA_PROJECT_1/JL_FILES/TestStruct.jl:1

```

I followed the example in the Julia Reference manual under **Case Study: Rational** , but I’m still not clear what’s wrong with the code above.

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [December 18, 2022, 1:00pm UTC](https://discourse.julialang.org/t/inner-constructor-error/91811/2 "2022-12-18T13:00:20Z")

</div>

`TestStruct{T}` is a parameteric type. Because of that you need to return `new{T}(...)` from the inner constructor.

Btw. you don’t need the `:: T` in the body of the inner constructor, because the elements of `Vector{T}` are already of type `T`.

---

<div class="post-metadata">

**Author:** ![Bananthahally](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bananthahally/32/222983_2.png) [@Bananthahally](https://discourse.julialang.org/u/Bananthahally)\
**Post date:** [December 18, 2022, 1:03pm UTC](https://discourse.julialang.org/t/inner-constructor-error/91811/3 "2022-12-18T13:03:31Z")

</div>

Thanks for that lightning response, @fatteneder

It works fine with the “new{T}(…)” option! 😀
