Compilation errors.

Hi there. My environment is Ubuntu 14.04; C++ compiler is g++14

1
2
public : void legendreTransform (int NN,complex TotFourierTransf[][NN],complex GaussLegTransf[][NN], PhiLimits phiBounds)
  {


Errors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
g++ -std=c++14 sphere_perspective.cpp
sphere_perspective.cpp:551:70: error: use of parameter outside function body before ‘]’ token
   public : void legendreTransform (int NN,complex TotFourierTransf[NN][NN],complex GaussLegTransf[NN][NN],
                                                                      ^
sphere_perspective.cpp:551:74: error: use of parameter outside function body before ‘]’ token
   public : void legendreTransform (int NN,complex TotFourierTransf[NN][NN],complex GaussLegTransf[NN][NN],
                                                                          ^
sphere_perspective.cpp:551:75: error: expected ‘)’ before ‘,’ token
   public : void legendreTransform (int NN,complex TotFourierTransf[NN][NN],complex GaussLegTransf[NN][NN],
                                                                           ^
sphere_perspective.cpp:551:76: error: variable or field ‘complex’ declared void
   public : void legendreTransform (int NN,complex TotFourierTransf[NN][NN],complex GaussLegTransf[NN][NN],
                                                                            ^
sphere_perspective.cpp:551:76: error: expected ‘;’ at end of member declaration
sphere_perspective.cpp:551:84: error: ‘GaussLegTransf’ does not name a type
   public : void legendreTransform (int NN,complex TotFourierTransf[NN][NN],complex GaussLegTransf[NN][NN],                                                                                    ^


Why?

Thanks, - Alex
Last edited on
Try using a different name for your formal parameter NN, as it seems to be identical to the size of the array you are using for the other parameters.
Thank you Zhuge.

This is the result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
g++ -std=c++14 sphere_perspective.cpp
sphere_perspective.cpp:551:70: error: ‘LOB’ was not declared in this scope
   public : void legendreTransform (int NN,complex TotFourierTransf[][LOB],complex GaussLegTransf[][LOB],
                                                                      ^
sphere_perspective.cpp:551:74: error: expected ‘)’ before ‘,’ token
   public : void legendreTransform (int NN,complex TotFourierTransf[][LOB],complex GaussLegTransf[][LOB],
                                                                          ^
sphere_perspective.cpp:551:75: error: variable or field ‘complex’ declared void
   public : void legendreTransform (int NN,complex TotFourierTransf[][LOB],complex GaussLegTransf[][LOB],
                                                                           ^
sphere_perspective.cpp:551:75: error: expected ‘;’ at end of member declaration
sphere_perspective.cpp:551:83: error: ‘GaussLegTransf’ does not name a type
   public : void legendreTransform (int NN,complex TotFourierTransf[][LOB],complex GaussLegTransf[][LOB],
                                                                                   ^
Hi,

Just something extra:

Always compile with the warning levels at their highest:

g++ -std=c++14 -Wall -Wextra -pedantic-errors sphere_perspective.cpp -o sphere_perspective

Can you show the context of how are you calling this function?

Last edited on
@TheIdeasMan thank you, but I don't understand why the calling code would be important? In this particular case I am converting a large gfortran program to c++. The program works but there are some issues I don't like and this is why I undertake this conversion. The calling part has not been converted yet and the whole code is kind of hard to penetrate. I think this routine should compile no questions asked. I had similar issues with c++11.

Why is the calling routine important for you?

Thank you, - Alex
Why is the calling routine important for you?


You are right, it doesn't matter yet.

Why is there no scope for your function definition? As in:

void sphere_perspective::legendreTransform(....){}

Edit: Presumably sphere_perspective is the class name?

Hope this helps :+)
Last edited on
> error: ‘LOB’ was not declared in this scope
> void legendreTransform (int NN,complex TotFourierTransf[][LOB],complex GaussLegTransf[][LOB],
you need to set the "width" of the matrix, it is not simply a place holder.
That means that your function will only work with matrices with that number of columns.

http://www.cplusplus.com/forum/articles/17108/
@TheIdeasMan, sphere_perspective.cpp is a file name. I just discovered a serious problem and the solution if found can answer all my pains. It all began with my inability to use double complex in this package. Look:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 #include <iostream>
#include <array>
#include "fft.h"         // #include "complex.h"
#include<iomanip>
#include <cmath>
#include <stdio.h>       /* printf */
#include <fstream>       // std::ofstream
#include "gauss_legendre.c"
using namespace std;
std::ofstream outFileOutput;
typedef std::complex<double> dcomp;

typedef struct PhiLimits PhiLimits;
struct PhiLimits
{
   double theta;
   double phiLower;
   double phiUpper;
};


The code above is the include statements and a couple of definitions for the file sphere_perspective.cpp.

fft.h is a header file from this website:

http://www.librow.com/articles/article-10/appendix-a-1

These are the first few lines:

1
2
3
4
5
6
7
fft.h

#ifndef _FFT_H_
#define _FFT_H_
#include "complex.h"
class CFFT
{ 


It shows that "complex.h" is included but it is a "private complex.h" This file is here:

http://www.librow.com/articles/article-10/appendix-b-1

file gauss_legendre.c does not have complex numbers, only double.

Now if I include the first typedef: typedef std::complex<double> dcomp; which I really need I get a compile error:

1
2
3
sphere_perspective.cpp:13:14: error: ‘complex’ in namespace ‘std’ does not name a template type
 typedef std::complex<double> dcomp;
              ^

If I include this statement: #include <complex.h> among other headers in sphere_perspective.cpp file the typedef std::complex<double> dcomp; statement compiles but it messes up lines and lines of my other code (Librow FFT routines). I copied Librow FFT source code and have used it before extensively. This is the website for Librow FFT:

http://www.librow.com/articles/article-10

So, it is serious confusion for me, a tangle and I don't know how to untangle it.

Thanks, - Alex


Last edited on
@TheIdeasMan, sphere_perspective.cpp is a file name


The reason I asked, is that you had public : void legendreTransform (...){} so that must be part of a class definition; there was a brace, so the function definition must be implicitly inline. But it is much better to split the files into .hpp and .cpp files. From what I can see, there seems to be too much going on inside sphere_perspective.cpp

Why do you #include a C file? Should only include header files, split them up too.

using namespace std; isn't recommended either.

It shows that "complex.h" is included but it is a "private complex.h" This file is here:


By "private complex.h" , do you mean that is another library implementation, not the STL one? I would be inclined to put all the LIBROW stuff into it's own namespace, then you can scope it. That might help the confusion below. Consider putting your own code in it's own namespace as well.

If I include this statement: #include <complex.h> among other headers in sphere_perspective.cpp file the typedef std::complex<double> dcomp; statement compiles but it messes up lines and lines of my other code (Librow FFT routines). I copied Librow FFT source code and have used it before extensively. This is the website for Librow FFT:


If you want std::complex, you need #include <complex> , not #include <complex.h> which might find the LIBROW complex header file, or a different C implementation. Use quotes for anything other than standard include files.

file gauss_legendre.c does not have complex numbers, only double.

But why do you now want to use std::complex ? The LIBROW is expecting their complex class, hence the messing up of the Librow FFT routines, when you use std::complex ? What does the gauss_legendre.c file look like? Will have to figure out how to interface with that.

Maybe you can upload your entire project to a hosting service, like github or similar? If not willing to make it public, PM me the link to it. I could have a go, and see what happens :+) It might take a day or two, it's 04:40 at this end, and I have a thing to do Sunday Arvo.

Regards :+)

@TheIdeasMan thank you. It is plenty. I actually was thinking about throwing out the Librow code out too.

gauss_legendre.c is here:

http://www.holoborodko.com/pavel/numerical-methods/numerical-integration/

It is all about numerical integration. One has to download a .zip file from this link which I did. It is a neat bunch of sets of coordinates and weights for numerical integration which I have used in my gfortran variant of this software.

Yes, "complex.h" is not STD. It is a file in my directory, copied from LIBROW.

gauss_legendre.c has nothing to do with this set of problems. I don't really use the code there, I use arrays only.

Thanks, - Alex
Last edited on
OK, no worries :+)

I hope it all goes well for you.
OK, I am making a progress but I need to crack a problem for the next step. Now the statement

typedef std::complex<double> dcomp;

is accepted but I need to use the dot operator dcomp.Re(), dcomp.Im(). How can I do it? The compiler gives me an error when I try to use the dot.

Sorry for the post. dcomp.real() works as well as dcomp.imag().

Thank you. - Alex
Last edited on
It shouldn't, `dcomp' is a class, not an object.
Thank you fellas for your help which has been invaluable. I just compiled all my 2300 lines of code. Some of the modifications followed from the post by @TheIdeasMan. I am marking this thread as solved but I still see some problems ahead.

Thanks, - Alex
Topic archived. No new replies allowed.