# Fallback Constructor for All Subtypes

**URL:** <https://discourse.julialang.org/t/fallback-constructor-for-all-subtypes/92011>\
**Category:** General Usage\
**Created:** [December 22, 2022, 4:21pm UTC](https://discourse.julialang.org/t/fallback-constructor-for-all-subtypes/92011 "2022-12-22T16:21:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [December 22, 2022, 4:21pm UTC](https://discourse.julialang.org/t/fallback-constructor-for-all-subtypes/92011/1 "2022-12-22T16:21:12Z")

</div>

I have a series of structs that are all subtypes of the same abstract type. They can all be constructed with the same logic, but I’d like to have unique constructor names.

```julia
abstract type AbstractThing end

struct Thing1 <: AbstractThing
    val
end
struct Thing2 <: AbstractThing
    val
end

# what I'm trying to do
function (t::T)() where {T <: AbstractThing}
    t("blah")
end

Thing1()
# Thing1("blah")
Thing2()
# Thing2("blah")

```

But after several iterations of trying to define the function, I can’t seem to get it to define a function for all subtypes.  
I’m aware that I could just do `construct(::Type{T}) where {T <: AbstractThing} = T("blah")`, but I like the ergonomics of using the normal constructor syntax using the types’ names.

---

<div class="post-metadata">

**Author:** ![werpers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/werpers/32/42610_2.png) [@werpers](https://discourse.julialang.org/u/werpers)\
**Post date:** [December 22, 2022, 4:59pm UTC](https://discourse.julialang.org/t/fallback-constructor-for-all-subtypes/92011/2 "2022-12-22T16:59:02Z")

</div>

Perhaps this is what you want:

```julia
function (T::Type{<:AbstractThing})()
    T("blah")
end

```
