…或者在模块接口单元声明它们就足够了?
测试.cpp:
module;
#include <iostream>
export module M;
export
template<typename>
class T
{
public:
void foo() const
{ std::cout << "T" << std::endl; }
};
// export <-- NOT exported
template<>
class T<int>
{
public:
void foo() const
{ std::cout << "T<int>" << std::endl; }
};
主.cpp:
import M;
int main()
{
T<int> x;
x.foo();
return 0;
}
输出:
$ rm -f gcm.cache/* && $(HOME)/gcc-master/bin/g++ -O3 -fmodules-ts test.cpp main.cpp -o foo && ./foo
T<int>
$ $(HOME)/gcc-master/bin/g++ --version
g++ (GCC) 11.0.0 20210128 (experimental)