I'm getting a 'base class undefined' error in some module-based C++ code I'm writing. I've reduced it to the following MCVE. The non-module equivalent compiles fine. I don't understand why the modularized code here fails. Please could someone explain why I'm getting the error and how, if possible, to fix it.
Here's the module interface unit -
// mcve.ixx
export module mcve;
export class X
{
friend class F; // (1)
};
export
template<typename T>
class A
{
};
export class B: public A<X>
{
};
// (2)
export class F: public B
{
};
and the cpp file showing where the compiler error is reported.
// main.cpp
import mcve;
int main()
{
// X x; // (3)
// A<X> ax; // (4)
// F f; // (5)
B b; // error C2504: 'B': base class undefined
}
Interestingly, removing either of the friend class F; at (1) or the whole class F declaration at (2) results in successful compilation.
Equally, uncommenting either of (3), (4) or (5) also works.
This is with Microsoft Visual Studio 2022 v17.2 (Platform toolset v143)(CL version 19.32.31328) and either /std:c++20 or /std:c++latest.