Template fails in function header

G

Guest

I'm getting error C2062: type 'float' unexpected and error C2065: 'complex' : undeclared identifier when I try to compile this
#include "stdafx.h
#include <iostream> //Consol I/
#include <time.h> //So I can measure how long it take
#include <complex> //Complex math suppor

void fourn(complex <float> data[], int nn[], int ndim, int isign

...


If I simply declare a variable of type complex <float> and assign values to it, no errors

int main(

using namespace std
..
float Re, Im
..
complex <float> fData[1024]
..
for(i = 0; i < 1024; i++

Re = (float)rand()
Im = (float)rand()
fData.real(Re); //This gives odd results. Works ok with constant
fData.imag(Im)
..


..
cout << "Re is " << Re << " Im is " << Im << endl
cout << "fData[13] is " << fData[13] << endl
cout << "fData[13].real is " << fData[13].real() << ". fData[13].imag is " << fData[13].imag() << endl
..


This is beyond me. If I can declare and use the template variable, why can't I pass it as a function parameter

Cheers

Peter.
 
C

Carl Daniel [VC++ MVP]

Peter said:
I'm getting error C2062: type 'float' unexpected and error C2065:
'complex' : undeclared identifier when I try to compile this:
#include "stdafx.h" #include <iostream> //Consol I/O
#include <time.h> //So I can measure how long it takes
#include <complex> //Complex math support

void fourn(complex <float> data[], int nn[], int ndim, int isign)

std::complex said:
{
...
}

If I simply declare a variable of type complex <float> and assign
values to it, no errors.

int main()
{
using namespace std;
...
float Re, Im;
...
complex <float> fData[1024];
...
for(i = 0; i < 1024; i++)
{
Re = (float)rand();
Im = (float)rand();
fData.real(Re); //This gives odd results. Works ok with
constants fData.imag(Im);
...
}

...
cout << "Re is " << Re << " Im is " << Im << endl;
cout << "fData[13] is " << fData[13] << endl;
cout << "fData[13].real is " << fData[13].real() << ".
fData[13].imag is " << fData[13].imag() << endl; ...
}

This is beyond me. If I can declare and use the template variable,
why can't I pass it as a function parameter?


Because inside main you have a using namespace std, but you don't have one
at file scope, so you need to use the fully qualified name in the function
declaration.

....unless you've left something important out of the code you've shown here,
that is. If the missing std:: isn't the problem, re-post with a complete
sample that you think should compile.

-cd
 
G

Guest

Carl Daniel wrote
Because inside main you have a using namespace std, but you don't have on
at file scope, so you need to use the fully qualified name in the function>>declaratio

Thank you Carl, that was it exactly. One step forward
Cheers

Peter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top