作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要能够调用一个正在寻找复杂数据结构(伪代码)vector::deque::vector(uint8_t)::iterator 的迭代器的函数。我需要能够用 deque::vector(uint8_t); 调用它我不知道如何“迭代”它。
在下面的代码段中,我尝试使用 someMoreBytes 双端队列结构调用 MyFunkyFunc 函数。
#include <cstdlib>
#include <vector>
#include <deque>
#include "stdint.h"
using namespace std;
void MyFunkyFunc(std::vector<std::deque<std::vector<uint8_t>>>::iterator itsIt)
{
}
int
main(int argc, char** argv)
{
std::vector<std::deque<std::vector < uint8_t>>> bunchaBytes;
std::deque<std::vector<uint8_t>> someMoreBytes;
//... Put at least one element in bunchaBytes
MyFunkyFunc(bunchaBytes.begin());
MyFunkyFunc(someMoreBytes); // Problem is here
return 0;
}
这个代码 stub 是接近原始代码的部分;我无法对 MyFunkyFunc 函数进行任何修改,因为它位于我必须链接的库中。非常感谢
最佳答案
如果我们假设 MyFunkyFunc
被正确实现为接受迭代器参数的模板:
template <typename I>
void MyFunkyFunc (I itsIt) {
//...
}
然后,您可以只传递 someMoreBytes
的地址,因为 vector 的迭代器的行为与 vector 元素的地址相同。
MyFunkyFunc(&someMoreBytes);
否则,你需要重新定义someMoreBytes
为单个元素vector
,并传入begin()
,就像你用 bunchaBytes
做了。
关于c++ - 如何将 deque>>vector>>bytes 迭代到函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57879528/
我是一名优秀的程序员,十分优秀!