问题
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
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};
}
thank you
回答1:
The error messages are the result of you trying to initialize a std::vector
with 2 double
s:
std::vector<Something> x(somedouble, otherdouble);
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: 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);
or
response[k+1] = {float(pos[k].x), float(pos[k].y)};
来源:https://stackoverflow.com/questions/16886865/error-double-is-not-a-class-struct-or-union-type