# Can structs have static fields?

**URL:** <https://discourse.julialang.org/t/can-structs-have-static-fields/48970>\
**Category:** General Usage\
**Tags:** struct\
**Created:** [October 25, 2020, 9:34am UTC](https://discourse.julialang.org/t/can-structs-have-static-fields/48970 "2020-10-25T09:34:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [October 25, 2020, 9:34am UTC](https://discourse.julialang.org/t/can-structs-have-static-fields/48970/1 "2020-10-25T09:34:03Z")

</div>

Does Julia have something similar to static class members in C++, whose values are shared across all objects of the class? If not, is there a good way to emulate it? I don’t want it to be a constant global variable, since I need the variable to be computed at run time.

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [October 25, 2020, 9:40am UTC](https://discourse.julialang.org/t/can-structs-have-static-fields/48970/2 "2020-10-25T09:40:46Z")

</div>

You want a dynamically valued property that is shared across all instances of a particular type? Sounds like you should use a function.

```julia
prop(x::MyType) = # some calculation

```
