# Classes nested in namespace

**URL:** <https://root-forum.cern.ch/t/classes-nested-in-namespace/58038>\
**Category:** Newbie\
**Tags:** root\
**Created:** [February 2, 2024, 9:59pm UTC](https://root-forum.cern.ch/t/classes-nested-in-namespace/58038 "2024-02-02T21:59:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![georgi\_petkov](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/georgi_petkov/32/35603_2.png) [@georgi\_petkov](https://root-forum.cern.ch/u/georgi_petkov)\
**Post date:** [February 2, 2024, 9:59pm UTC](https://root-forum.cern.ch/t/classes-nested-in-namespace/58038/1 "2024-02-02T21:59:07Z")

</div>

Hello,

I have the following issue,  
I simple case.  
I have declared a class

```auto
#pragma once

#ifndef EsbIO_hpp
#define EsbIO_hpp 1

#include <string>
//#include "G4VPhysicalVolume.hh"
#include "TObject.h"

namespace core {
namespace esbcore {

class EsbIO : public TObject
{
public:
    EsbIO();
    ~EsbIO();

    int ExportTGeoVolume(std::string path_to_file);
private:
    ClassDef(EsbIO,6);
};

}
}
#endif

```

and its implementation file as:

```auto
#include "core/io/EsbIO.hpp"
#include "TGeoManager.h"

namespace core {
namespace esbcore{

EsbIO::EsbIO()
{
}

EsbIO::~EsbIO()
{
}

int EsbIO::ExportTGeoVolume(std::string path_to_file){
    return gGeoManager->Export(path_to_file.c_str());
}

}
}

```

The linkdef.h is  
#ifdef **CINT**

```auto
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ nestedclass;
#pragma link C++ nestedtypedef;

#pragma link C++ namespace core+;
#pragma link C++ namespace core::esbcore+;

#pragma link C++ class core::esbcore::EsbIO+;

#endif

```

building with the root macro

```auto
ROOT_GENERATE_DICTIONARY( G___esbio ${CMAKE_CURRENT_SOURCE_DIR}/io/EsbIO.hpp 
                            LINKDEF ${CMAKE_CURRENT_SOURCE_DIR}/EsbioLinkDef.h
                            MODULE esbio} )

```

It generates the pcm, rootmap file etc.  
But when I execute it from a .C file as

```auto
..
std::string path = "<some_path>/test_core.gdml";
core::esbcore::EsbIO* tt = new core::esbcore::EsbIO()
...

```

I get the following error:

```auto
In file included from input_line_8:1:
/home/framework/build/core/test.C:20:5: error: use of undeclared identifier 'core'
    core::esbcore::EsbIO* tt = new core::esbcore::EsbIO();
    ^
/home/framework/build/core/test.C:20:36: error: use of undeclared identifier 'core'
    core::esbcore::EsbIO* tt = new core::esbcore::EsbIO();

```

What mistake have I made in the linkdef file or somewhere else?

\_ROOT Version: Build from source → tags/v6-28-04  
\_Platform: Linux mint 21.2  
\_Compiler: g++ (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0

---

<div class="post-metadata">

**Author:** ![georgi\_petkov](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/georgi_petkov/32/35603_2.png) [@georgi\_petkov](https://root-forum.cern.ch/u/georgi_petkov)\
**Post date:** [February 3, 2024, 10:20am UTC](https://root-forum.cern.ch/t/classes-nested-in-namespace/58038/2 "2024-02-03T10:20:39Z")

</div>

Removing the namespace , the .C works.  
I found several discussions on the issue (some quite old, but I guess relevant)

- [Namespace in my own library](https://root-forum.cern.ch/t/namespace-in-my-own-library/32365)
- [RootTalk: adding my classes in a namespace to cint](https://root.cern/root/roottalk/roottalk00/0407.html)
- [RootTalk: RE: [ROOT] namespace problem](https://root.cern.ch/root/roottalk/roottalk00/3227.html)

And from one answer I found that if the lib contains a class without a namespace , loading the class will load the library. But since namespaces can span multiple libraries, that is why they don’t cause automatic loading of the library and thus the above error.  
Anyone having other information?

---

<div class="post-metadata">

**Author:** ![georgi\_petkov](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/georgi_petkov/32/35603_2.png) [@georgi\_petkov](https://root-forum.cern.ch/u/georgi_petkov)\
**Post date:** [February 4, 2024, 6:21am UTC](https://root-forum.cern.ch/t/classes-nested-in-namespace/58038/3 "2024-02-04T06:21:30Z")

</div>

Issue was that the root\_generate\_dictionary macro creates a file .pcm in the . This pcm, once created upon first usage of the EsbIO, is not updated. Unloading the module also does not remove the pcm file. Thus the initial EsbIO class was not within a namespace, subsequently adding a namespace regardless of the linkdef.h file, it will give strange errors- from. Undefined members to linkage errors.  
The solution was to add in the build script for cmake to remove the pcm file.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [February 6, 2024, 11:16am UTC](https://root-forum.cern.ch/t/classes-nested-in-namespace/58038/4 "2024-02-06T11:16:55Z")

</div>

Thanks @georgi_petkov for memorialising this process in a post: hopefully it will be useful for other users in the future!
