c++ - 这里使用了哪个 std::vector 构造函数?
问题描述
我有一些代码(它来自https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Validation_layers):
uint32_t glfwExtensionCount = 0;
const char** glfwExtensions;
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
std::vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount); // which constructor is used here?
一切都可以编译并且可以工作,但是我不知道向量构造函数中发生了什么。
解决方案
那是
template< class InputIt >
vector( InputIt first, InputIt last,
const Allocator& alloc = Allocator() );
(https://en.cppreference.com/w/cpp/container/vector/vector中的#4 )。它从一系列输入迭代器构造一个向量。
C++ 迭代器被设计为与指针兼容,即指针是有效的迭代器。
推荐阅读
- ios - 如何在 Swift 中使用协议初始化 UIViews 和 UIViewControllers
- c# - C# / LINQ 新手,查询中的分组无法解决
- c# - 调用 Application.Calculate 中断正在编辑的公式
- machine-learning - 机器学习中超参数和启发式的区别?
- python-2.7 - Python:将一个键值对转换为字典中的字符串
- java - 带有自签名证书的 SSLHandshakeException
- php - 在 WooCommerce 的感谢页面上从 $order 获取数据
- c# - 错误 CS1056:意外字符“?”
- java - 获取异步任务的返回
- assembly - 对齐,模数;“因此,它可以在每个函数入口处依赖 ESP = 12 模 16。”