2012-03-04 126 views
1

我想运行我的代码,但我在每个位置都收到错误,我调用了我的两个返回数组的方法。C3861:找不到标识符;方法返回数组C++

我刚刚开始编程,不知道这件事有什么问题。

我发布了下面的整个代码。

// Test.cpp : Defines the entry point for the console application. 
#include "stdafx.h" 
#include <iostream> 
#include <cmath> 
#include <conio.h> 

using namespace std; 

int Log2(int n) 
{ 
int m; 
int ct = 0; 
m = n; 
while(m) 
{ 
    m = m >> 1; 
    ct++; 
} 
ct-=1; //correction step 

return ct; 
} 

int power(int n) 
{ 
int x = 1; 
    for (int i=0;i<n;i++) 
     x *= 2; 

    return x; 
} 

void FFT(short int dir,long m,double *x,double *y) 
{ 
int endoffile; 
    long n,i,i1,j,k,i2,l,l1,l2; 
    double c1,c2,tx,ty,t1,t2,u1,u2,z; 

    n = 1; 
n = power(m); 

double xreal[16];// = new double[n]; 
double xcomplex[16];// = new double[n]; 

    i2 = n >> 1; 
    j = 0; 
    for (i=0;i<n-1;i++) 
    { 
     if (i < j) { 
      tx = x[i]; 
      ty = y[i]; 
      x[i] = x[j]; 
      y[i] = y[j]; 
      x[j] = tx; 
      y[j] = ty; 
    } 
    k = i2; 
    while (k <= j) { 
     j -= k; 
     k >>= 1; 
    } 
    j += k; 
} 

for(int k=0; k<n;k++) 
{ 
double *find = getter(k, x, y, n); 
xreal[k] = find[0]; 
xcomplex[k] = find[1]; 
} 
if (dir=1) 
{ 
for(int k=0; k<n; k++) 
{ 
x[k] = xreal[k]; 
x[k]/=n; 
y[k] = xcomplex[k]; 
y[k]/=n; 
} 
} 
} 

double* getter(int k, double *x,double *y, int n) 
{ 
double realret = 0.0; 
double imagret = 0.0; 

for(int n2=0; n2<=n/2 - 1; n2++) 
{ 
    double *a = complexgetter(n/2,n2,k); 
    realret+=a[0] * x[2*n2]-a[1] * y[2 * n2]; 
    imagret+=a[1]*x[2*n2]+a[0]*y[2*n2]; 
} 
double *mult= complexgetter(n,1,k); 
for(int n4=0; n4<=n/4 - 1; n4++) 
{ 
    double *a = complexgetter(n/4,n4,k); 
    double tmpreal=a[0]*x[4*n4+1]-a[1]*y[4*n4+1]; 
    double tmpimag=a[1]*x[4*n4+1]+a[0]*y[4*n4+1]; 
    realret+=tmpreal*mult[0]-tmpimag*mult[1]; 
    imagret+=tmpreal*mult[1]+tmpimag*mult[0]; 
} 
mult=complexgetter(n,3,k); 
for(int n4=0; n4<=n/4 - 1; n4++) 
{ 
    double *a = complexgetter(n/4,n4,k); 
    double tmpreal=a[0]*x[4*n4+3]-a[1]*y[4*n4+3]; 
    double tmpimag=a[1]*x[4*n4+3]+a[0]*y[4*n4+3]; 
    realret+=tmpreal*mult[0]-tmpimag*mult[1]; 
    imagret+=tmpreal*mult[1]+tmpimag*mult[0]; 
} 
double *ret = 0;// = new double[2]; 
ret[0]=realret; 
ret[1]=imagret; 
return ret; 
} 

double* complexgetter(int N, int i, int k) 
{ 
double PI = 3.14159265358979323846; 

double value = -2*PI; 
value/=N; 
value*=i; 
value*=k; 
double *ret = 0; 
ret[0]=cos(value); 
ret[1]=sin(value); 
return ret; 
} 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
double x1[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; 
double y1[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; 
    // double y1[16] = {0}; 
int m1 = 4; 
int dir1 = 1; 

FFT(dir1, m1, x1, y1); 

    return 0; 
} 

以下是我得到的错误。

test.cpp(67): error C3861: 'getter': identifier not found 
test.cpp(90): error C3861: 'complexgetter': identifier not found 
test.cpp(94): error C3861: 'complexgetter': identifier not found 
test.cpp(97): error C3861: 'complexgetter': identifier not found 
test.cpp(103): error C3861: 'complexgetter': identifier not found 
test.cpp(106): error C3861: 'complexgetter': identifier not found 

感谢您的帮助。

回答

2

问题是在定义之前,您使用的是gettercomplexGetter。 C/C++本质上是从上到下读取文件。所以在功能FFT它看到使用getter,并不知道这是什么。您需要添加一个声明来告诉C/C++该方法的形状才能被处理。

将这个上面的FFT功能

double* getter(int k, double *x,double *y, int n); 
double* complexgetter(int N, int i, int k); 

通知的;在这里就结束了。这使它成为一个声明。本质上是对编译器的承诺,您将在后面定义具有此形状的函数

0

该代码中没有方法,只有函数。函数必须在使用前声明。如果没有递归,那很简单 - 只需在首次使用之前定义函数。