Im trying to include a module within another module, but i can't compile due to the following error:
"Cannot build the following source files because there is a cyclic dependency between them: Module1.ixx depends on Module2.ixx depends on Module1.ixx."
Code i tried:
// Module1.ixx
export module Module1;
import Module2;
export class modClass1_
{
public:
modClass1_() {};
~modClass1_() {};
int getV() { return V; };
int getOtherModuleV() { modClass2_ mc2; return mc2.V; };
int V = 1;
};
// Module2.ixx
export module Module2;
import Module1;
export class modClass2_
{
public:
modClass2_() {};
~modClass2_() {};
int getV() { return V; };
int getOtherModuleV() { modClass1_ mc1; return mc1.V; };
int V = 2;
};
Any help/suggestion will be appreciated.
Environment: Visual Studio 2019 | MSVC-2019 | C++20 | Windows 10 Pro
Create module interface units that do not have circular dependencies.
A module interface unit is somewhat similar in purpose to a header file.
A module interface unit has
export modulein it. The primary module interface unit has no partition name.Remove the implementation of
{ modClass2_ mc2; return mc2.V; };fromexport Module1;primary module interface unit, do that in the module implementation unit ofModule1, and includeimport Module2;there.and the circular dependency is broken.