'std :: vector <double> :: iterator'没有名为'begin'的成员</double>

时间:2013-01-05 21:14:00

标签: c++ iterator

所以我试图在一个大的C ++ STL向量上执行递归(一个非常简单的分裂基数递归蝴蝶的代码),我使用迭代器来调用递归,但它不能正常工作,因为我一直在收到错误。

#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

template <typename T>
class fft_data{
public: 
vector<T> re;
vector<T> im;

};

void inline split_radix_rec(vector<double>::iterator r,vector<double>::iterator i, int sgn,int N) {
if (N == 1) {
    return;
} else if (N == 2) {
    for (int k = 0; k < N/2; k++) {
        int index = 2*k;
        int index1 = index+1;
        double taur =  *(r+index1);
        double taui =  *(i+index1);

        *(r+index1) = *(r+index) - taur; 
        *(i+index1) = *(i+index) - taui; 

        *(r+index) = *(r+index) + taur; 
        *(i+index) = *(i+index) + taui; 
    }
    N=N/2;
} else {
    int m = N/2;
    int p = N/4;

    double PI2 = 6.28318530717958647692528676655900577;
    double theta =  -1.0 * sgn * PI2/N;

    double S =  sin(theta);
    double C =  cos(theta);

    double PI6 =  3.0*6.28318530717958647692528676655900577;
    double theta3 =  -1.0 * sgn * PI6/N;

    double S3 =  sin(theta3);
    double C3 =  cos(theta3);

    double wlr =  1.0;
    double wli =  0.0;

    //T wl2r = (T) 1.0;
    //T wl2i = (T) 0.0;

    double wl3r =  1.0;
    double wl3i =  0.0;

    double tau1r,tau1i,tau2r,tau2i;
    double ur,ui,vr,vi;

    for (int j = 0; j < p; j++) {
        int index1 = j+m;
        int index2 = index1+p;
        int index3 = j+p;

        tau1r = *(r+index1);
        tau1i = *(i+index1);

        tau2r = *(r+index2);
        tau2i = *(i+index2);

        ur = tau1r + tau2r;
        ui = tau1i + tau2i;

        vr = sgn* (tau2r - tau1r);
        vi = sgn* (tau2i - tau1i);

        *(r+index2) = *(r+index3) - vi;
        *(i+index2) = *(i+index3) + vr;

        *(r+index1) = *(r+j) - ur;
        *(i+index1) = *(i+j) - ui;

        *(r+index3) = *(r+index3) + vi;
        *(i+index3) = *(i+index3) - vr;

        *(r+j) = *(r+j) + ur;
        *(i+j) = *(i+j) + ui;

    }

    split_radix_rec(r.begin(),i.begin(),sgn,m);
    split_radix_rec(r.begin()+m,i.begin()+m,sgn,p);
    split_radix_rec(r.begin()+m+p,i.begin()+m+p,sgn,p);
}


}


int main() {
vector<double> u,v;
for (int i = 0; i < 256; i++) {
    u.push_back(i);
    v.push_back(i);
}

int sgn = 1;
int N = 256;
split_radix_rec(u.begin(),v.begin(),sgn,N);
return 0;
}

以下是我遇到的错误

main.cpp:93:21: error: 'std::vector<double>::iterator' has no member named 'begin'

6行93,94,95(从split_radix_rec函数中调用的三个split_radix_rec()函数)中的相同错误。这是一个更大的代码的一部分,所以我希望它适用于STL向量。我做错了什么?

3 个答案:

答案 0 :(得分:3)

如错误所述,您正在begin()上调用std::vector<double>::iterator

您应该在std::vector<double>上调用它,以便它可以返回std::vector<double>::iterator

答案 1 :(得分:1)

ri本身就是代码中的迭代器(开始)。

尝试:

split_radix_rec(r,i,sgn,m);
split_radix_rec(r+m,i+m,sgn,p);
split_radix_rec(r+m+p,i+m+p,sgn,p);

答案 2 :(得分:0)

有太多的代码可以为您提供简明的答案,但错误清楚地表明您在向量迭代器而不是向量上调用begin() 。这发生在split_radix_rec递归调用。您可能已经打算这样做了:

split_radix_rec(r,i,sgn,m);
split_radix_rec(r+m,i+m,sgn,p);
split_radix_rec(r+m+p,i+m+p,sgn,p);