在C++14中,我如何初始化一个包含文本字符串的全局constexpr
std::pair
的std::array
?以下代码无法工作:#include <array>
constexpr std::array<std::pair<int, const char[]>, 3> strings = {
{0, "Int"},
{1, "Float"},
{2, "Bool"}};
int main() {
}
std :: array <std :: string,2> s = {“Hi”,“Hello”};
和std :: array <std :: string,2> s = {{“Hi, “Hello”}};
在C++14之后被认为是相同的(对于非constexpr数组)。为什么这里不适用同样的规则? - aepstd::array<std::string, 2> s={"hi", "hello"};
、std::array<std::string, 2> s={{"hi", "hello"}};
、std::array<std::string, 2> s={{"hi"}, {"hello"}};
、std::array<std::string, 2> s={{{"hi"}, {"hello"}}};
来看看它们之间的差异。感谢您的解释。 - aep