错误:' double '不是类、结构或联合类型
error: ‘double’ is not a class, struct, or union type
我遇到了这个问题,我收到了一段非常敏感的代码,它应该在一个嵌套的向量中存储70 x,y协调集,然后将其转换为浮点数组;
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};
}
谢谢
错误消息是您试图用2个double
s初始化std::vector
的结果:
std::vector<Something> x(somedouble, otherdouble);
std::vector
认为这些双精度对象是输入迭代器,指定了它应该加载的范围。
因为在你发布的代码中没有出现这样的东西,我们只能猜测实际的问题。你需要做一个最小的例子,精确地再现你的问题,并在一个新的问题中发布整个代码。
EDIT1:是的,它是:response[k+1] = {pos[k].x,pos[k].y};
由于x
和y
是双精度而不是浮点数,您触发双迭代器构造函数来创建一个临时向量来分配给response[k+1]
,而不是初始化列表构造函数。将行改为
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)};
相关文章:
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- <badref> 当使用 CallInst::CreateMalloc 作为结构类型时
- 给定一个C++嵌套的私有结构类型,是否有从文件范围静态函数访问它的策略
- 为什么"具有常量成员的结构"类型的指针不能指向"具有非常量成员的结构"?
- 查找声明为结构类型 C++ 的数组末尾
- C++ - 将结构类型的数组传递给用户定义的函数
- PowerShell 使用结构类型参数调用 C++ DLL 的导出函数
- NTTP 的结构类型:为什么所有成员都必须是公共的?
- 当我尝试访问结构类型时,我收到 std::bad_variant_access 异常
- 承诺可以使用结构类型吗?
- 填充模板化结构类型的结构成员
- 如何为结构类型变量赋值
- 在 c++ 中将结构类型转换为无符号字符*
- 在 c++ 中将一种结构类型分配给另一种类型
- 如何访问在 c++ 中在类内声明的结构类型指针变量?
- 确定输入"conscalc: calc"的类型时出错。不能联合编码器。具有不同字段集的结构类型
- 无法将结构类型的标识符设置为 nullptr;
- 结构类型成员的默认构造函数中的默认参数
- 如何在执行期间终止(或返回)具有结构类型的自动函数
- 在 stl 中迭代结构类型的队列