如何不使用'export'关键字从模块中导出函数和类? 我正在调查一个在我的PET项目中使用C++模块TS的机会。对我来说,一个重要的用例是包装遗留的头文件
假设我有一个包含一些函数和类的头文件,std.io.ixx:如何不使用'export'关键字从模块中导出函数和类? 我正在调查一个在我的PET项目中使用C++模块TS的机会。对我来说,一个重要的用例是包装遗留的头文件,c++,module,visual-studio-2017,c++20,c++-modules,C++,Module,Visual Studio 2017,C++20,C++ Modules,假设我有一个包含一些函数和类的头文件,std.io.ixx: int f(int x) { return 2 + x; } import std.io; int main() { f(5); } 根据,我使用以下命令编译模块: cl /c /experimental:module /module:name std.io /module:export std.io.ixx cl /c /experimental:module main.cxx 这给了我一个新文件
int f(int x)
{
return 2 + x;
}
import std.io;
int main()
{
f(5);
}
根据,我使用以下命令编译模块:
cl /c /experimental:module /module:name std.io /module:export std.io.ixx
cl /c /experimental:module main.cxx
这给了我一个新文件std.io.ifc
。然后我在另一个源文件中使用这个模块,main.cxx:
int f(int x)
{
return 2 + x;
}
import std.io;
int main()
{
f(5);
}
它是使用以下命令编译的:
cl /c /experimental:module /module:name std.io /module:export std.io.ixx
cl /c /experimental:module main.cxx
编译给了我以下错误:
main.cxx(5): error C3861: 'f': identifier not found
因此,我们可以看到,模块中的标识符没有导出。我可以通过在每个要导出的标识符之前手动添加export
关键字来解决这个问题,但对于包装旧标题的用例来说,这是不可能的
我做错了什么?如何从标题导出所有可能的标识符?我认为有两件事不对:
std.
开头。当我尝试这样做时,我得到了错误
error C3674: could not find standard library module 'std.io'
如果尚未安装Visual Studio的标准库模块组件,则可能不会出现此错误。不过,我不确定这一点ixx
时,我得到了与您相同的错误