简体   繁体   中英

'std::vector<double>::iterator' has no member named 'begin'

So I am trying to perform recursion ( A very simple code for split radix recursive butterflies) on a large C++ STL vector and I am using iterators to call the recursion but it isn't working as I keep getting errors.

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

Here are the errors I am getting

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

6 Identical errors on lines 93,94,95 (the three split_radix_rec() functions called from within the split_radix_rec function). This is part of a much larger code so I want it to work for STL vectors. What am I doing wrong?

As the error states, you are calling begin() on a std::vector<double>::iterator .

You should call that on a std::vector<double> , so that it could return you a std::vector<double>::iterator .

r , i are itself iterators(begins) in your code.

Try:

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);

There is way too much code to give you a concise answer, but the error clearly states that you are calling begin() on a vector iterator instead of a vector . And that happens at the split_radix_rec recursive call. You may have intended this instead:

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM