- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是相关代码:
void init(int f, int h, std::vector<std::vector<double> > **offsets) {
for (int i = 0; i < 2 * h + 1; i++) { // for all frames
// vector of (x, y, d)'s
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
random_offsets(offsets[y][x]);
print_vecs(offsets[y][x]);
}
}
}
}
int main(int argc, char **argv) {
int h = 6;
Halide::Runtime::Buffer<uint8_t> frame[2*h + 1];
int f = 6;
for (int i = -h; i < h; i++) {
frame[i] = load_image("test1/small/" + std::to_string(f + i) + ".png");
}
W = frame[0].width();
H = frame[0].height();
std::vector<std::vector<double> > offsets[H][W];
init(6, h, offsets);
return 0;
}
我创建了一个 offsets
二维数组并将其传递给 init 函数。但这在编译时会出现以下错误:
note: candidate function not viable: no known conversion from 'std::vector<std::vector<double> > [H][W]' to
'std::vector<std::vector<double> > **' for 3rd argument
void init(int f, int h, std::vector<std::vector<double> > **offsets) {
我该如何解决这个问题?
在关注其中一条评论并更改为 vector ...(H, vector...)...我总共有以下代码:
void random_offsets(std::vector<std::vector<double> > &offsets) {
for (int i = 0; i < k; i++) {
std::vector<double> offset;
offset.push_back(W/3 * ((double) rand() / (RAND_MAX)) * 2 - 1);
offset.push_back(W/3 * ((double) rand() / (RAND_MAX)) * 2 - 1);
offsets.push_back(offset);
}
}
void init(int f, int h, std::vector<std::vector<double> > &offsets) {
for (int i = 0; i < 2 * h + 1; i++) { // for all frames
// vector of (x, y, d)'s
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
random_offsets(offsets[y][x]);
print_vecs(offsets[y][x]);
}
}
}
}
int main(int argc, char **argv) {
int h = 6;
Halide::Runtime::Buffer<uint8_t> frame[2*h + 1];
int f = 6;
for (int i = -h; i < h; i++) {
frame[i] = load_image("test1/small/" + std::to_string(f + i) + ".png");
}
W = frame[0].width();
H = frame[0].height();
std::vector<std::vector<double>> offsets(H, std::vector<double>(W));
init(6, h, offsets);
return 0;
}
但是我得到以下错误:
init.cpp:43:2: error: no matching function for call to 'random_offsets'
random_offsets(offsets[y][x]);
^~~~~~~~~~~~~~
init.cpp:14:6: note: candidate function not viable: no known conversion from 'std::__1::__vector_base<double, std::__1::allocator<double> >::value_type'
(aka 'double') to 'std::vector<std::vector<double> > &' for 1st argument
void random_offsets(std::vector<std::vector<double> > &offsets) {
^
似乎我真正需要的是,假设二维 vector 的二维数组不起作用,是:
std::vector<std::vector<std::vector<std::vector<double> > > > offsets(H, std::vector<std::vector<std::vector<double> > > (W, std::vector<std::vector<double> > (k, std::vector<double> (3))));
最佳答案
这std::vector<std::vector<double> > **offsets
不做你认为它做的事。这是一个指向 std::vector...
的指针.您可能正在寻找的是通过引用传递:
void init(int f, int h, std::vector<std::vector<double> > &offsets)
这符合您调用此函数的方式以及您在内部使用该对象的方式。
这里有一个很好的概述:What's the difference between passing by reference vs. passing by value?但我强烈建议您在这里研究一本很好的 C++ 书籍:The Definitive C++ Book Guide and List
关于c++ - 为什么我在这里得到 C++ no known conversion error?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58424539/
有没有人有嵌套 Intent 的好例子,尤其是在 #yes 和 #no 是子节点的情况下。我得到的情况是 API 返回的是 Intent 值,但输出文本来自“Anything else”! 最佳答案
我知道您可以转到 Watson Conversation 界面,右键单击工作区,然后下载工作区的 JSON,其中包含意图,如下所示:Is there any way to export intents
我能否在 Watson Conversation API 的对话流中使用节点条件中的意图置信度评级? 最佳答案 要做到这一点,请创建一个条件来寻找您的意图,然后检查置信度。 你会拥有的示例条件 #te
我找到了很多关于这个错误的帖子,但我可以找到克服它的方法。这是触发错误的代码: void main(){ float f{1.3}; } 为什么在初始化列表中没有像其他变量那样发生转换?例如,
我有以下代码。 #include using namespace std; class Base { public: virtual int f(){coutf(); ///base
Visual C++ 2017 和 gcc 5.4 产生 conversion from 'const unsigned char' to 'const float' requires a narro
我正在为 PIC18F2420 使用带有 xc8 1.35 编译器的 MPLABX 3.20,我收到了两个我不理解的奇怪警告: 这是生成警告的源代码之一 9 void write(Pin _Pin,
我正在尝试在 win32 API(无 mfc)上编写一些直接的 c++。有了这个更现代的 c++ 编译器,我得到: 警告 C4838:从“unsigned int”到“int”的转换需要收缩转换 它发
此代码采用用户输入(字符 C、T、B)和(int 0-24 和 0-60)来计算 parking 成本关于用户输入的车辆类型。 我怀疑错误发生在函数 charged 中,因此我无法在收到此错误的最后一
为什么在使用 tuple 或 Tuple 转换向量时会得到以下不同的结果? julia> a = [1, 2, 3] 3-element Vector{Int64}: 1 2 3 julia> tup
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 8年前关闭。 Improve t
我正在开发一个文件共享网站,我需要一种方法来对上传的文档进行截图。 该站点将支持多种文件格式,从纯文本到办公文档(doc、xls、ppt...)、视频(mpeg、avi...)、图像(jpg、gif、
在 VHDL 中是否有将整数类型对象转换为实数类型的通用转换函数? 这是针对测试平台的,因此可综合性不是问题。 最佳答案 您可以将整数转换为实数,如下所示: signal i: integer; si
如何在 Ocaml 中将字符串选项数据类型转换为字符串? let function1 data = match data with None -> "" | Some str -> s
我已经在 VHDL 中编写了一个算法,但是我有一条消息,我不明白“sra/sla 在这种情况下不能有这样的操作数。”。请问有什么帮助吗? library ieee; use ieee.std_logi
我经常需要将数据从一种类型转换为另一种类型,然后进行比较。一些运算符会先转换为特定类型,这种转换可能会导致效率损失。例如,我可能有 my $a, $b = 0, "foo"; # initial va
假设我在 IBM Watson 中配置了一个对话服务,可以识别以单词和片段形式给出的数字。例如,如果我有号码 1320 , 可以发送为 thirteen twenty或 thirteen two ze
也许我错过了一些显而易见的事情...在整个文档中,我似乎都认为Kotlin具有各种类型的序列,这些序列不能互操作。即使复制序列可能效率不高–当我需要将其作为语义相同但不同的类型传递给函数时,这也无济于
在我的Linux终端中,我想要使用QTcpSocket从qt运行以下“对话”: S user@domain:~ $ netcat 1.1.1.2 9230 R HELO SOME MORE I
我有一个模板函数,其中枚举类型转换为它的底层类型,工作正常,但我写了一个重载,它应该接受一个整数并返回它自己,它给我一个错误,指出 int 不是枚举类型。在我的模板中,这应该已经被过滤掉了。怎么了?
我是一名优秀的程序员,十分优秀!