The problem was I cannot properly separate the declaration & definition of a templated symbols such as classes, structs, functions, and many more. Before we could continue I have this quick statement on how I organized my work/project. We can skip this one and just go to "what I have Tried" section. thank you.
I have this kind of practices/standard way of doing c++20 module
. It was divided into 3 parts;
1. Primary Module Interface unit (*.ixx
)
- It can compose | import a list of all the module partitions available or other named-module.
- It can contains a declaration or with a definition for your needed symbols
2. (Optional) Module Partition unit (*.ixx
)
- same as number# 1.
3. (Optional) Module Implementation unit (*.cxx
)
- It should only had the definition/implementation for all the needed declared symbols you had.
--------------------------------------------------------------------------------------
[Directories]
/module-name
└─src
└─main
└─cpp
└─domain/name/module_name/pkg1
└─
dn-module_name-pkg1.ixx
//REM: primary-module-interface inside of this pkg1
└─
ClassOne.ixx
//REM: another module-interface/partition
└─
ClassOne.cxx
//REM: module-implementation
--------------------------------------------------------------------------------------
1. primary-module-interface (
dn-module_name-pkg1.ixx
)
export module domain.name.module_name.pkg1;
export import :ClassOne;
2. module-partition (
ClassOne.ixx
)
export module domain.name.module_name.pkg1:ClassOne;
namespace domain::name::module_name::pkg1 {
export class ClassOne {
public:
ClassOne();
virtual ~ClassOne();
};
}
export namespace $DN$MODULE_NAME$PKG1 = domain::name::module_name::pkg1;
export using $DN$MODULE_NAME$PKG1_ClassOne_t = typename $DN$MODULE_NAME$PKG1::ClassOne;
export typedef $DN$MODULE_NAME$PKG1_ClassOne_t ClassOne_t;
3. module-implementation (
ClassOne.cxx
)
module domain.name.module_name.pkg1:ClassOne;
namespace domain::name::module_name::pkg1 {
ClassOne::ClassOne() { }
ClassOne::~ClassOne() { }
}
We could add this another
primary-module-interface
(
dn-module_name.ixx
) to the upper level|directories|pkg;
--------------------------------------------------------------------------------------
[Directories]
/module-name
└─src
└─main
└─cpp
└─domain/name/module_name
└─
dn-module_name.ixx
//REM: primary-module-interface or my root mod-intf
└─pkg1
└─ ...
--------------------------------------------------------------------------------------
(
dn-module_name.ixx
)
export module domain.name.module_name;
export import domain.name.module_name.pkg1;
At the main entry point or the client side (*
.cxx
or
.cpp
or
.cppm
)
import domain.name.module_name.pkg1;
int main(...) {
ClassOne_t cOne;
}
What I have tried:
For our Templated classes, struct, logic, and etc
How do We
Define our
Declared templated symbols/classes/etc
from the
module-interface/partition
and then we try to
Implement it to a separate file:
module-implementation-unit
. Such like this:
*module-partition(
TemplateClassOne.ixx
)
export module domain.name.module_name.pkg1:TemplateClassOne;
namespace domain::name::module_name::pkg1 {
export template<typename T = int>
class TemplateClassOne {
public:
TemplateClassOne();
virtual ~TemplateClassOne();
}
}
*module-implementation(
TemplateClassOne.cxx
)
module domain.name.module_name.pkg1:TemplateClassOne;
namespace domain::name::module_name::pkg1 {
template<>
TemplateClassOne<>::TemplateClassOne() { }
TemplateClassOne<>::~TemplateClassOne() { }
}
How do we do it right? On this C++20 module, Is separating it was not possible?
NOTE: the keyword
"Symbols"
I'm using here it means: all the data types, structs, classes, functions, identifiers and so on