将赋值运算符与 make_pair 方法一起使用会生成 CLion 警告

Using an assignment operator with make_pair method generates a CLion warning

在我的程序中有一个数组对声明如下:

pair <string, int> mostOftenPairs[10];

当我想初始化它时:

for (short i = 0; i < 10; ++i)
    mostOftenPairs[i] = make_pair(std::string(), 0);

CLion 强调了发生赋值的行,当我将鼠标悬停在它上面时,出现此错误:

'pair::operator=(type)' is deleted

然而,程序运行没有任何问题,但我的问题是是否有任何方法用于为对赋值而不是'='?是否可以在同一行中初始化对数组?我的意思是类似于这个:

pair <string, int> mostOftenPairs[10] = make_pair(std::string(), 0);

Is it possible to initialise the array of pairs in the same line? I mean something similar to this one:

std::pair constructor

的文档所述,您无需执行任何操作即可默认初始化它们

1) Default constructor. Value-initializes both elements of the pair, first and second.

(重点是我的)所以 std::pair 的默认构造函数已经初始化(空字符串和 0 为 int),如果你不需要默认值使用 std::vector:

std::vector<std::pair<std::string,int>> mostOftenPairs( 10, std::make_pair( std::string(), 1 ) );