# Warning in \<MyClass\>: The data members of MyClass will not be stored, because it inherits from TObject but does not have its own ClassDef

**URL:** <https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597>\
**Category:** ROOT\
**Tags:** cling\
**Created:** [February 18, 2021, 1:25pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597 "2021-02-18T13:25:43Z")\
**Posts on this page:** 11\
**Page:** 1

<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:** [February 18, 2021, 1:25pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597/1 "2021-02-18T13:25:44Z")

</div>

Hello,  
in a standalone CMake project with ROOT integration, I get several of this type of compilation warnings from “metacling” for some derived classes that I create:

`Warning in <MyClass>: The data members of MyClass will not be stored, because it inherits from TObject but does not have its own ClassDef.`

I believe it happens when calling ROOT\_GENERATE\_DICTIONARY(…) CMake macro.

I would prefer not to define a ClassDef for these classes. Is there an empty ‘ClassDef’ macro or compilation flag / verbosity level to disable this warning explicitly, so that I do not get the command line filled with it, which makes it harder to find the real warnings?

Thanks in advance for the help!

* * *

_ROOT Version:_ 6.23/01  
_Platform:_ Ubuntu 18  
_Compiler:_ gcc, cmake

* * *

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [February 18, 2021, 2:04pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597/2 "2021-02-18T14:04:12Z")

</div>

Hello,

You can set `gErrorIgnoreLevel = kWarning`, but that will disable all ROOT warnings (edit: if the warning happens when calling ROOT\_GENERATE\_DICTIONARY, then what I suggested won’t help).

Regarding `ClassDef`, perhaps @Axel can answer.

---

<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:** [February 18, 2021, 5:18pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597/3 "2021-02-18T17:18:42Z")

</div>

> [@etejedor](#):
>
> `gErrorIgnoreLevel = kWarning`

Thanks for the reply. I tried adding this, but it did not work, because the error appears when compiling, not when running.

---

<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:** [February 18, 2021, 6:30pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597/4 "2021-02-18T18:30:28Z")

</div>

> which makes it harder to find the real warnings?

If you class inherits from TObject _AND_ you do not use a ClassDef then the data in those classes will not be saved (because the system relies on the overload of functions implemented in the linkdef, eg, `IsA` and `Streamer).

I.e. It is a **REAL** warning and actually in almost all cases an error.

Why do you prefer to not define a ClassDef? What is the advantage for you?

Why do you inherit from TObject?

Cheers,  
Philippe.

---

<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:** [February 18, 2021, 7:30pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597/5 "2021-02-18T19:30:59Z")

</div>

Thanks for the reply.

It is a GUI window, thus I do not want to save it or stream it.

`class MainWindow : public TGMainFrame`

In principle, I would have no problem of adding the ClassDef even if I do not need it. But the problem is that, if I add it, I am not able to use forward declaration in my header.

I use now:

```auto
class TGCheckButton;
class TGComboBox;
class TGLabel;
class TGHProgressBar;
class TGSpeedo;
class TGHtml;
class TGTab;
class TGToolBar;

(...)

private:
    TGTab* myTab{};
    TGTextButton* myButton{};
(...)

```

Without ClassDef, all works fine except for the metacling warning.  
With the ClassDef, that fails to compile, with the error:

```auto
Error in <CheckDefinition>: Missing definition for class TGTab, please #include its header in the header of MainWindow
In file included from input_line_8:3:
In file included from MainWindow.hpp:9:
/opt/root_bld/include/TGFrame.h:34:7: error: incomplete type 'TGTextButton' where a complete type is required

```

Thus, I prefer to keep my headers cleaner without extra includes and ClassDefs.

---

<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:** [February 18, 2021, 9:17pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597/6 "2021-02-18T21:17:55Z")

</div>

I think you can add those “missing” headers in the LinkDef file as:

```auto
#pragma link extra_include "TGTextButton.h"

```

(or maybe directly as `#include`)

---

<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:** [February 18, 2021, 10:09pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597/7 "2021-02-18T22:09:49Z")

</div>

Hmmm, but I do not have any LinkDef file in my CMake project.

As I just wanted a minimal GUI class deriving from TGMainFrame, I call the ROOT\_GENERATE\_DICTIONARY without using the LINKDEF argument, as done here:

> [@Classdef](https://root-forum.cern.ch/t/classdef/22337/5):
>
> As Philippe pointed out, you need to link against the generated dictionary of our class. Just changing slightly the CMakeLists.txt file like this should work. cmake\_minimum\_required(VERSION 2.8) project(tbjcAnalysis) list(APPEND CMAKE\_PREFIX\_PATH $ENV{ROOTSYS}) find\_package(ROOT) include(${ROOT\_USE\_FILE}) include\_directories(${ROOT\_INCLUDE\_DIRS}) add\_definitions(${GCC\_COVERAGE\_COMPILE\_FLAGS}) include\_directories(${PROJECT\_SOURCE\_DIR}/include) ROOT\_GENERATE\_DICTIONARY(G\_\_test include/test.h)…

Or is it a bad practice not to specify a LinkDef?

---

<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:** [February 18, 2021, 10:20pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597/8 "2021-02-18T22:20:12Z")

</div>

Well having a LinkDef let you control more carefully what the dictionary does and would give you an opportunity to suppress the warnings.

Alternatively you could try a relatively new alternative (so you mileage may vary) and remove the dictionary generation altogether and add a `ClassDefInline` macro (instead of the `ClassDef` macro).  
If it works in you case, it will simply your build while still letting you use forward declaration.

Cheers,  
Philippe.

---

<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:** [February 18, 2021, 11:10pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597/9 "2021-02-18T23:10:16Z")

</div>

Thanks for the tip, that inline solution works really great for me. No warnings when compiling, no warnings when running. And I do no need any more the extra hacks that I had added in my CMakeLists to suppress warnings, see [Silence GCC warnings in CMake C++ standalone project with ROOT classes and dictionaries](https://root-forum.cern.ch/t/silence-gcc-warnings-in-cmake-c-standalone-project-with-root-classes-and-dictionaries/43500) .

The only downside is that I have to add in my main.cpp file all the paths that are in my CMakeLists, hard-coding them by hand, as the files I want to #include depend on them:  
(which I did not need to do before when I generated the explicit dictionaries as CMake was taking care of all of it)

```auto
    gInterpreter->AddIncludePath("myprogram/submodule1/");
    gInterpreter->AddIncludePath("myprogram/core/");
    gInterpreter->AddIncludePath("/opt/boost/...");
    gInterpreter->AddIncludePath("/opt/mydriver/api");
    gInterpreter->Declare("#include \"MainWindow.hpp\"");//MainWindow.hpp includes headers that are located in the places above
    MainWindow window(...);

```

Or is there a more automated way of passing to TInterpreter the same include-paths as used in the CMakeLists.txt ?

Thanks for the awesome support.

---

<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:** [February 18, 2021, 11:16pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597/10 "2021-02-18T23:16:20Z")

</div>

> Or is there a more automated way of passing to TInterpreter the same include-paths as used in the CMakeLists.txt ?

I am afraid that on our side the way to do it is to generate a dictionary … 😉

On your side, you could create a custom target that generate a (source or header) file that contains the information.

Cheers,  
Philippe.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [March 4, 2021, 11:17pm UTC](https://root-forum.cern.ch/t/warning-in-myclass-the-data-members-of-myclass-will-not-be-stored-because-it-inherits-from-tobject-but-does-not-have-its-own-classdef/43597/11 "2021-03-04T23:17:03Z")

</div>

Closed on March 4, 2021, 11:17pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
