小编A R*_*A R的帖子

为什么在模块中导出类型别名(例如 std::vector<std::string> )允许在某些内部分区中同时使用 std::vector 和 std::string ?

我目前正在使用 Visual Studio 2022 Update 17.1.6,我发现导出类型别名有一些有趣的东西。由于我不明白的原因,当我导出某些数据类型的类型别名(例如std::vector<std::string>在模块接口文件中)时,我可以在导入它的文件中使用std::vector<>和。std::string例如:

modInterface.ixx

export module words;
import <iostream>
import <vector>;
import <string>;
...
export using Words = std::vector<std::string>;
...
Run Code Online (Sandbox Code Playgroud)

在内部分区中:

modInternalPartition.cpp

module words:wordsIP;
import words;

//This compiles as expected
Words wordStorage;

//Why does my compiler sees below as correct, and compiles it without error?
std::vector<int> numStorage = { 1, 2, 3, 4 };

//Why does my compiler also sees below as correct, and compiles it without error?
std::string text = …
Run Code Online (Sandbox Code Playgroud)

c++ string templates vector c++20

9
推荐指数
1
解决办法
952
查看次数

标签 统计

c++ ×1

c++20 ×1

string ×1

templates ×1

vector ×1