Without the export and module annotations, g++ will compile the following
example. We have a module type (module structure) MS, and a module
instantiation MI. None of these gets revealed to the outside. The module can be
compiled separatedly, no dependencies with an importing program. :private tells
the compiler that the export section is complete. The template <T>calc gets
exported, but because the underlying module structure remains hidden, it can't
be used from an importing program. However, the template defines some
properties of the module.
export module M1;
class MS; //forward declaration
export typedef MS *M; // for exported typedef
export M init(int);
export M upd(M);
export template <typename T>
T calc(T mv) {
mv->r = mv->v;
return mv; };
module :private; // from now on no export decls anymore
struct N { string r,v;} ;
struct MS {
N a; int r,v;
M init(int v) { set(v,"start"); r = 0; a.r = ""; return this; }
M upd() { calc(&a); return calc(this); }
void set(int iv, string sv) { v = iv; a.v = sv;}
} MI;
M init(int v) { return MI.init(v); }
M upd(M mv) { return mv->upd(); }
Run