gpt4 book ai didi

c++ - 你怎么能 emplace_back 错误的类型呢?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:41:48 27 4
gpt4 key购买 nike

我有一个 double vector 。但是我打错了

我打算这样写:

std::vector<double> timestamp;

但我是这样写的:

std::vector<std::vector<double>> timestamp;

但是,这样编译

timestamp.emplace_back(a_double_timestamp)

我正在安置一个 double进入std::vector<std::vector<double>> . double不是 std::vector<double>

最佳答案

double隐式转换为 size_type , 作为 the vector constructor 的参数:

explicit vector( size_type count );

因此,如果你通过 2.3 , 创建的 vector 大小为 static_cast<std::vector<double>::size_type>(2.3) == 2 .

std::vector<double> v{2.3}也可以在没有任何警告的情况下编译。

关于c++ - 你怎么能 emplace_back 错误的类型呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52061877/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com