c++ - 将 vector <int>转换为const vector <const int>

标签 c++ casting constants

如何转换 vector<int>常量vector<const int>

我已经尝试过static_cast<const vector<const int>>(array)并使用该值而不进行强制转换。都没有编译。

最佳答案

您无法转换 std::vector<int>const std::vector<const int> .

此外,使用 std::vector<const int> 没有任何意义。根本不。它并不比 const std::vector<int> 为您提供更多的安全性。 .

不仅如此,C++ 不允许构造 std::vector<const T> 。请参阅Does C++11 allow vector<const T>?了解更多信息。

关于c++ - 将 vector <int>转换为const vector <const int>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38276124/

相关文章:

c++ - C++ 中的大文件支持

c++ - 在 C++ 中存储类型

python - 设置Python文件中值的允许数据类型/类型转换的范围

objective-c - 在 Cocoa 中解码整数和其他掩码

c++ - 了解构造函数的一些具体情况

c++ - 栅栏实际上如何在 C++ 中工作

c++ - 测量静态、堆和堆栈内存? (c++, Linux - Centos 7)

c - 错误: a value of type "void *" cannot be assigned to an entity of type "float *"

c++ - std::set 迭代器自动 const

c++ - 按 const 值返回的目的?