Thanks to
c++20 - C++ Modules Forward Declaring Entity from Another Module - Stack Overflow[
^], I got a solution working. It is:
import A;
import B;
int main() {
A a;
B b;
a.setB(&b);
b.setA(&a);
return 0;
}
export module A;
export class B;
export class A {
private:
B* b;
public:
void setB(B* b_) { b = b_; }
};
export module B;
export class A;
export class B {
private:
A* a;
public:
void setA(A* a_) { a = a_; }
};
The only problem is that although it works, Visual Studio Intellisense is showing errors that "incomplete class type "A" is not allowed" on both "A a;" and "a.setB(&b);" lines. Those errors will be annoying to see, even though the compiled program doesn't treat them as errors! :rolleyes:
If I rearrange the 'import A' 'import B' lines, then the errors become 'incomplete class type "B" is not allowed' on the 'b' lines. :anotherRolleye:
Other than the errors that aren't errors, I like this way better because it eliminates headers. Unless I'm overlooking something else.