错误:'double'不是类,结构或联合类型 [英] error: ‘double’ is not a class, struct, or union type

查看:855
本文介绍了错误:'double'不是类,结构或联合类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到这个问题,我收到一个非常敏感的代码片段,它应该存储70 x,y坐标在嵌套向量中的集合,然后将其转换为浮点数组;
这里是:

I've got this problem that I recieve o a very sensitive piece of code, it is supposed to store sets of 70 x,y coordonance in a nested vector and later convert that into a float array; here it is:

 vector<vector<vector<float> > > KnownPoints ;
 float* returnPoint = new float[knownFaces.size()*70*2];
    for(int i=0;i<KnownPoints.size();i++){
        for(int k=0;k<KnownPoints[i].size();k++){
           returnPoint[i*70*2+k*2] = KnownPoints[i][k][0];
           returnPoint[i*70*2+k*2+1] = KnownPoints[i][k][1];
        }
    }

但我不断收到这些错误:

But I keep getting these errors:

/usr/include/c++/4.7/bits/stl_vector.h:1147:24:   required from ‘void std::vector<_Tp, _Alloc>::_M_initialize_dispatch(_InputIterator, _InputIterator, std::__false_type) [with _InputIterator = double; _Tp = float; _Alloc = std::allocator<float>]’
/usr/include/c++/4.7/bits/stl_vector.h:393:4:   required from ‘std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = double; _Tp = float; _Alloc = std::allocator<float>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<float>]’
LibEmotion.cpp:69:47:   required from here
/usr/include/c++/4.7/bits/stl_iterator_base_types.h:166:53: error: ‘double’ is not a class, struct, or union type
/usr/include/c++/4.7/bits/stl_iterator_base_types.h:167:53: error: ‘double’ is not a class, struct, or union type
/usr/include/c++/4.7/bits/stl_iterator_base_types.h:168:53: error: ‘double’ is not a class, struct, or union type
/usr/include/c++/4.7/bits/stl_iterator_base_types.h:169:53: error: ‘double’ is not a class, struct, or union type
/usr/include/c++/4.7/bits/stl_iterator_base_types.h:170:53: error: ‘double’ is not a class, struct, or union type


b $ b

我真的很感谢帮助手,
Amine

I would really be thankful for a helping hand , Amine

Edit1:
这里的代码片段我认为是导致它:

here's the code snippet i think is causing it:

vector<cv::Point> pos;
vector<vector<float> > response;
for (int k = 0; k < pos.size(); k++) {
            response[k+1] = {pos[k].x,pos[k].y};
        }

谢谢

推荐答案

错误消息是您尝试使用2 double 初始化 std :: vector / code> s:

The error messages are the result of you trying to initialize a std::vector with 2 doubles:

std::vector<Something> x(somedouble, otherdouble);

std :: vector 输入迭代器指定它应该加载的范围。

std::vector thinks those doubles are input iterators specifying a range it's supposed to load from.

由于在您发布的代码中没有显示任何内容,我们只能猜测实际的问题。你需要做一个最小的例子,准确再现你的问题,并在一个新的问题中发布整个代码。

Since nothing like that appears in the code you posted, we can only guess at the actual problem. You need to make a minimal example that exactly reproduces your problem and post the entire code in a new question.

EDIT1:是的,它是: response [k + 1] = {pos [k] .x,pos [k] .y}; 因为 x $ c> y 是double而不是浮点数,你触发两个迭代器构造函数,使一个临时向量分配给 response [k + 1] 而不是初始化列表构造函数。将行更改为

Yep, there it is: response[k+1] = {pos[k].x,pos[k].y}; Since x and y are doubles instead of floats, you are triggering the two-iterator constructor to make a temporary vector to assign to response[k+1] instead of the initializer-list constructor. Change the line to

response[k+1].push_back(pos[k].x);
response[k+1].push_back(pos[k].y);

response[k+1] = {float(pos[k].x), float(pos[k].y)};

这篇关于错误:'double'不是类,结构或联合类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆