исходный файл foo.h :
Код: Выделить всё
namespace N {
struct X {};
int d();
int e();
inline int f(X, int = d()) { return e(); }
int g(X);
int h(X);
}
< /code>
Интерфейс модуль M: < /p>
module;
#include "foo.h"
export module M;
template int use_f() {
N::X x; // N::X, N, and :: are decl-reachable from use_f
return f(x, 123); // N::f is decl-reachable from use_f,
// N::e is indirectly decl-reachable from use_f
// because it is decl-reachable from N::f, and
// N::d is decl-reachable from use_f
// because it is decl-reachable from N::f
// even though it is not used in this call
}
template int use_g() {
N::X x; // N::X, N, and :: are decl-reachable from use_g
return g((T(), x)); // N::g is not decl-reachable from use_g
}
template int use_h() {
N::X x; // N::X, N, and :: are decl-reachable from use_h
return h((T(), x)); // N::h is not decl-reachable from use_h, but
// N::h is decl-reachable from use_h
}
int k = use_h();
// use_h is decl-reachable from k, so
// N::h is decl-reachable from k
Module M implementation:
module M;
int a = use_f(); // OK
int b = use_g(); // error: no viable function for call to g;
// g is not decl-reachable from purview of
// module M's interface, so is discarded
int c = use_h(); // OK
Подробнее здесь: https://stackoverflow.com/questions/745 ... le-in-c-20