错误:'double'不是类,结构或联合类型

时间:2013-06-02 20:13:56

标签: c++ opencv vector multidimensional-array g++

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

 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];
        }
    }

但我一直收到这些错误:

/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

我真的很感谢你伸出援手, 胺


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

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};
        }

谢谢

1 个答案:

答案 0 :(得分:3)

错误消息是您尝试使用2 std::vector s初始化double的结果:

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

std::vector认为那些双精度数是输入迭代器,指定了它应该从中加载的范围。

由于您发布的代码中没有出现这种情况,我们只能猜测实际问题。您需要制作一个完全重现问题的最小示例,并将整个代码发布到一个新问题中。

EDIT1:是的,它是:response[k+1] = {pos[k].x,pos[k].y};因为xy是双精度而不是浮点数,所以你要触发双迭代器构造函数来创建一个临时向量来分配给response[k+1]而不是initializer-list构造函数。将行更改为

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)};