|
|
坏坏的小熊猫 · C++标准库之std::begin、std: ...· 4 周前 · |
|
|
暴走的伤疤 · 向量数据类型 | TiDB 文档中心· 2 周前 · |
|
|
烦恼的核桃 · sceasy | 单细胞跨平台数据互通 | ...· 1 年前 · |
|
|
聪明伶俐的泡面 · python协程总结 - fengf233 ...· 2 年前 · |
|
|
鼻子大的柑橘 · 马莹 山东大学主页平台管理系统--中文主页· 2 年前 · |
|
|
没有腹肌的海豚 · 钉钉发布“魔法棒”;金山办公推出 WPS ...· 2 年前 · |
|
|
稳重的钥匙 · Python3.9环境安装mysqlclie ...· 2 年前 · |
我有一个
std::vector<uint8_t[1115]>
,我想在里面存储一个
char*
。我不明白我为什么要把这个字符*放进向量中。也许这很愚蠢,但我试过这个:
char* myCharArray = new char[1115];
std::vector<uint8_t[1115]> myVector;
myVector.push_back(reinterpret_cast<uint8_t*>(myCharArray));
我不明白为什么这不管用。错误如下:
error: no matching function for call to ‘std::vector<unsigned char [1115]>::push_back(uint8_t*)’
发布于 2015-01-16 10:36:26
你有两个问题:
vector
的元素必须是可复制的、可构造的和可分配的,但数组不能。这意味着您不能合法地拥有数组的
vector
。如果您正在使用C++11或更高版本,则可以使用
std::vector<std::array<uint8_t, 1115>>
。
std::array
类型是数组的可复制包装器。
push_back
只需复制对象即可将其插入到向量中的对象。不能将
char*
(或任何其他点)复制到数组中。但是,如果您遵循我在(1)中的建议,则可以完全避免指针,只需将其设置为
std::array<uint8_t, 1115> myCharArray;
。
如果
std::array
对您不可用,您可以使用
std::vector<std::vector<uint8_t>>
,只需确保内部向量大小合适即可。
在大多数的
new
中,您可能会对C++感兴趣。
https://stackoverflow.com/questions/27981753
复制相似问题
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2024 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号: 粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
|
|
暴走的伤疤 · 向量数据类型 | TiDB 文档中心 2 周前 |
|
|
烦恼的核桃 · sceasy | 单细胞跨平台数据互通 | anndata | loom | seurat | sce | monocle | 格式转换 - Life·Intelligence - 博客园 1 年前 |
|
|
鼻子大的柑橘 · 马莹 山东大学主页平台管理系统--中文主页 2 年前 |