我已经编写了下面的代码,我收到了错误。我做错了什么?
float sampledEnergies ( float ionDistance[], float ionEnergy[])
{
float samTime[1000];
float simPos[1000];
float closeEnergy[1000];
float close;
int maxSamples = chamberLength / (driftVel * adcSampleRate);
for (int i = 0; i < maxSamples; i++)
{
samTime[i] = i * adcSampleRate;
simPos[i] = chamberLength - (driftVel * samTime[i]);
printf("%.2f\t%.2f\n",samTime[i],simPos[i]);
close = lower_bound(ionDistance.begin(),ionDistance.end(), simPos[i]);
for (int j = 0; j < maxSamples; j++)
{
if (close = ionDistance[j])
{
closeEnergy[i] = ionEnergy[j];
}
}
}
}
以上是代码,错误如下。
TBraggSimulation_v1.cpp: In function ‘float sampledEnergies(float*, float*)’:
TBraggSimulation_v1.cpp:37: error: request for member ‘begin’ in ‘ionDistance’, which is of non-class type ‘float*’
TBraggSimulation_v1.cpp:37: error: request for member ‘end’ in ‘ionDistance’, which is of non-class type ‘float*’
答案 0 :(得分:0)
您的ionDistance
是一个指针(指向数组的第一个元素),而不是标准库容器。您的代码尝试调用begin
和end
,它们仅为容器定义。
要获取指针的一系列迭代器,请使用:
lower_bound(ionDistance, ionDistance + n, simPos[i]);
此处n
是ionDistance
数组中元素的数量。我不明白你的代码足以暗示它等于maxSamples
;如果不是,请在函数中添加一个参数:
float sampledEnergies ( float ionDistance[], float ionEnergy[], size_t numIons)
{
lower_bound(ionDistance,ionDistance + numIons, simPos[i]);
}