本文介绍了请求“ ionDistance”中的成员“ begin”(非类类型“ float *”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了下面的代码,并且收到错误消息。我在做什么错?

I have written the code below and I am receiving the error. What am I doing wrong?

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

} 

上面是代码,错误如下。

The above is the code and the error is as follows.

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*’


推荐答案

您的 ionDistance 是一个指针(指向数组的第一个元素),而不是标准库容器。您的代码尝试调用开始 end ,它们仅为容器定义。

Your ionDistance is a pointer (to a first element of an array) and not a standard-library container. Your code tries to call begin and end, which are only defined for containers.

要获取指针的迭代器范围,请使用:

To obtain a range of iterators for a pointer, use:

lower_bound(ionDistance, ionDistance + n, simPos[i]);

此处 n 是其中的元素数您的 ionDistance 数组。我对您的代码不够了解,无法建议它等于 maxSamples ;如果不是,则向函数添加参数:

Here n is the number of elements in your ionDistance array. I don't understand your code enough to suggest it's equal to maxSamples; if it's not, add a parameter to your function:

float sampledEnergies ( float ionDistance[], float ionEnergy[], size_t numIons)
{
    lower_bound(ionDistance,ionDistance + numIons, simPos[i]);
}

这篇关于请求“ ionDistance”中的成员“ begin”(非类类型“ float *”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 00:40