C++ 是否有必要使用export对导出实体的模板专门化进行注释?
…或者在模块接口单元声明它们就足够了吗 test.cpp:C++ 是否有必要使用export对导出实体的模板专门化进行注释?,c++,c++20,c++-modules,C++,C++20,C++ Modules,…或者在模块接口单元声明它们就足够了吗 test.cpp: module; #include <iostream> export module M; export template<typename> class T { public: void foo() const { std::cout << "T" << std::endl; } }; // export <-- NOT exported te
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; }
};
模块;
#包括
出口模块M;
出口
模板
T类
{
公众:
void foo()常量
{std::cout导出只影响名称查找和链接。这两者都与任何类型的模板专门化或实例化无关,因此它们永远不需要导出。这里的标准是这样说的。我认为其目的是不需要导出
,因为部分专门化不需要导出()@cpprearner我看到你开门了。我会留意的。谢谢。
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)