初始化结构的std ::向量
Initializing std::vector of structs
我希望将此类型的一堆对象添加到std :: vector。
typedef struct
{
int handle;
} Handle;
句柄是在我无法更改的C API标头中定义的。
我目前正在这样做,但想知道它是否可以作为单线。
Handle handle1 = {12};
Handle handle2 = {13};
std::vector<Handle> handles = boost::assign::list_of(handle1)(handle2);
i使用C 98编译器。
只需写一个make_handle
函数:
Handle make_handle(int handle) {
Handle ret = { handle };
return ret;
}
相关文章:
- std::向量与传递值的动态数组
- std::sort()函数无法对向量的一部分进行排序
- 如何在旧c++中初始化const-std向量
- 如何检查两个 std::向量在小于 O(n) 的时间复杂度内是否相等
- 使用 std::vector::reverse_iterator 将 int 序列化为字节向量?
- 在 std::无符号字符的向量处存储 int 的十六进制表示形式
- 如何在向量中删除 std::function<void()>?
- 从 std<Derived>::shared_ptr 的向量返回 std::shared_ptr<Base>
- 将无符号字符的向量存储在数组中会给我 std::bad_alloc
- std::find,返回所有找到的值的替代方法,而不仅仅是存在重复的向量的第一个值
- 如何创建一个类,以便向量工作 std::vector<MyClass<int>> v{ 1,2,3 };
- C++ STD 函数运算符:有没有一种方法可以通过函数将一个向量映射到另一个向量上?
- 对的排序向量 (std::vector<pair<int, int>>) 按对的第一个元素搜索并更新第二个元素值
- 使用 std::sort 对向量进行稳定排序
- 如何在C++中将字节向量(std::vector<uint8_t>)转换为不同的uint32_t,uint16_t和uint8_t变量
- C++程序中的向量 std::bad_alloc 错误
- 如何诊断保存和加载位向量(std::vector)的奇怪行为<bool>?
- 用SWIG包裹一个4维标准::向量 std::complex。<float>
- C++ 在抛出字符串向量"std::out_of_range"的实例后调用的终止
- 如何初始化 std::向量 std:固定长度对与默认值