到目前为止,在Visual Studio 2015中我可以使用C ++模块做什么? (使用实验开关) [英] What can I do with C++ modules in Visual Studio 2015 so far? (using the experimental switch)
问题描述
所以我在看一个视频,显示Visual Studio 2015 Update 1,他们提到实验性C ++模块支持(约8分钟)。
此版本实际支持多少功能?
我会喜欢,如果有人会显示某种代码示例,使用Visual Studio /实验开关,以便我可以开始玩弄。 >
这里是如何获得一个简单的例子使用Update 1 RTM,基于链接在@ dxiv的回答视频中的说明。 / p>
首先是模块定义文件 mine.ixx
。编译它: cl / c / experimental:module mine.ixx
。这将使 mine.obj
和 mine.ifc
:
模块矿;
export
{
int sum(int x,int y);
}
int sum(int x,int y){return x + y; }
下一页 main.cpp
模块,使用 cl / c / experimental:module main.cpp
编译。这将使 main.obj
:
#include< iostream&
import mine;
int main()
{
std :: cout< sum(2000,15)< std :: endl;
return 0;
}
然后使用 link * .obj
,你应该得到一个
main.exe
。
注意,这不工作非常好从VS内部,因为它不明白模块施加的顺序要求 - 你必须手动修改你的项目文件来做这个。
So I was looking at a video showing the news in 'Visual Studio 2015 Update 1' and they mentioned experimental C++ module support (about 8 minutes in).
How much of this feature is actually supported in this version?
I would love if someone would show some kind of code example that works with the Visual Studio /experimental switch, so that I can start playing around with it.
Here's how to get a simple example working with the Update 1 RTM, based on the instructions in the video linked in @dxiv's answer.
First, the module definition file mine.ixx
. Compile it with: cl /c /experimental:module mine.ixx
. This will make mine.obj
and mine.ifc
:
module mine;
export
{
int sum(int x, int y);
}
int sum(int x, int y) { return x + y; }
Next main.cpp
that uses the module, compile with cl /c /experimental:module main.cpp
. This will make main.obj
:
#include <iostream>
import mine;
int main()
{
std::cout << sum(2000, 15) << std::endl;
return 0;
}
Then link these with link *.obj
, and you should get a main.exe
.
Note that this doesn't work very well from inside VS at the moment since it doesn't understand the ordering requirements that the modules impose - you'd have to manually modify your project files to do this.
这篇关于到目前为止,在Visual Studio 2015中我可以使用C ++模块做什么? (使用实验开关)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!