现代C++语言特性(不断更新)
C++20 modules
参考网站:https://zh.cppreference.com/w/cpp/language/modules
测试平台:VS2019
需要包含:

VS配置:
- C++20标准:
![image]()
- 启动modules:
![image]()
- Compile as C++ Module Code (/interface )
![image]()
测试程序:

helloworld.cpp:
export module helloworld; // 模块声明
import <iostream>; // 导入声明
export void hello() { // 导出声明
std::cout << "Hello world!\n";
}
main.cpp:
import helloworld; // 导入声明
int main() {
hello();
}
C++20 concept
g++-10,参考:https://www.cnblogs.com/hebohang/p/15990146.html
编译: g++-10 test.cc -Wall -Wextra -std=c++20
出现编译错误,并有提示:
cc1plus: note: set ‘-fconcepts-diagnostics-depth=’ to at least 2 for more detail
于是我改成:g++-10 test.cc -Wall -Wextra -std=c++20 -fconcepts-diagnostics-depth=2
果然编译信息更多了。




浙公网安备 33010602011771号