现代C++语言特性(不断更新)

C++20 modules

参考网站:https://zh.cppreference.com/w/cpp/language/modules

测试平台:VS2019

需要包含:
image

VS配置:

  • C++20标准:
    image
  • 启动modules:
    image
  • Compile as C++ Module Code (/interface )
    image

测试程序:
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
果然编译信息更多了。

posted @   hebh  阅读(109)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示