# Automatic public getter setter generation in a TObject inherited class

**URL:** <https://root-forum.cern.ch/t/automatic-public-getter-setter-generation-in-a-tobject-inherited-class/49956>\
**Category:** Evolution Proposals, Apps & Ideas\
**Tags:** root\
**Created:** [May 12, 2022, 10:13am UTC](https://root-forum.cern.ch/t/automatic-public-getter-setter-generation-in-a-tobject-inherited-class/49956 "2022-05-12T10:13:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier\_Galan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/javier_galan/32/29662_2.png) [@Javier\_Galan](https://root-forum.cern.ch/u/Javier_Galan)\
**Post date:** [May 12, 2022, 10:13am UTC](https://root-forum.cern.ch/t/automatic-public-getter-setter-generation-in-a-tobject-inherited-class/49956/1 "2022-05-12T10:13:25Z")

</div>

Hello!

I am just wondering if there is a way to implement automatically public getter and setter methods inside our ROOT-ified classes.

> **[GitHub - rest-for-physics/framework: The main project containing the core C++...](https://github.com/rest-for-physics/framework)**
>
> The main project containing the core C++ classes defining framework behaviour and primordial analysis and helper tools. It centralises all other rest-for-physics repositories through submodules. - ...

We are lazy while implementing our c++ classes ☹

Perhaps this feature already exists and we are not aware of. Anyhow, it would be great if we could add a modifier (e.g `{get/set}`) at each data member that triggers the get/set methods implementation at the dictionary generation stage.

For example, if we would write something like

```auto
Int_t fDummyMember = 0; //< {get/set}

```

Then at the dictionary generation stage it would automatically generate

```auto
Int_t GetDummyMember() { return fDummyMember; }
void SetDummyMember( const Int_t &dummyMember ) { fDummyMember = dummyMember; }

```

I add @lobis in CC 🙂

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [May 12, 2022, 5:34pm UTC](https://root-forum.cern.ch/t/automatic-public-getter-setter-generation-in-a-tobject-inherited-class/49956/2 "2022-05-12T17:34:30Z")

</div>

If the get and setter are that simply, did you consider “just” making the member public?

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [May 12, 2022, 9:30pm UTC](https://root-forum.cern.ch/t/automatic-public-getter-setter-generation-in-a-tobject-inherited-class/49956/3 "2022-05-12T21:30:28Z")

</div>

This feature does not exist as far as I know.

If you really like to use the Get/Set formalism over the public-member solution that pcanal suggested, for consistency against other classes or methods, one workaround would be to just use a preprocessor macro, see [c++ - getter/setter generation with multiline stringfy macro - Stack Overflow](https://stackoverflow.com/a/26354463/7471760)

This way, you avoid relying on ‘undefined’ meta-behavior of dictionary generation (some user in the future might remove things thinking it’s just a comment, but it’s actually changing code). Which happened to me several times when using ROOT GUI Classes, where comments, exclamation marks, etc., play a role in signals, transients, context menu, ClassDef titles, etc.  
Which is not the most robust programming choice in my opinion.

---

<div class="post-metadata">

**Author:** ![Javier\_Galan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/javier_galan/32/29662_2.png) [@Javier\_Galan](https://root-forum.cern.ch/u/Javier_Galan)\
**Post date:** [May 13, 2022, 7:23am UTC](https://root-forum.cern.ch/t/automatic-public-getter-setter-generation-in-a-tobject-inherited-class/49956/4 "2022-05-13T07:23:45Z")

</div>

Yes @pcanal we though about making them public, but as @ferhue pointed out, I think we feel more comfortable using the `Set/Get` formalism.

Thanks for the insights!
