But it is a constant already!!!

Hi all.

There are header and source files storing input data. Similarly there are header and source files storing structures.
Now I have 2 questions:

1) How I can define structures with their members in a header file?
2) How I can define e.g.: struct 'name' "variable'[constant]. And this constant is defined in 'input' source file. I mean compiler gives error "expression must have a constant value" when I use n3D in structures.h and .cpp.

input.h
1
2
3
4
5
6
#include <iostream>

extern const int n0D;
extern const int n1D;
extern const int n2D;
extern const int n3D;

input.cpp
1
2
3
4
5
6
#include "inputs.h"

const int n0D = 9261;
const int n1D = 120;
const int n2D = 600;
const int n3D = 1000;


Here is the structures.h which belongs to my first question:

structures.h
1
2
3
4
5
6
7
#include "input.h"

extern struct sources
{	
    extern float pres[n3D];
    extern float all[n3D];
};


structures.cpp
1
2
3
4
5
6
7
#include "structures.h"

struct sources
{	
    float pres[n3D];
    float all[n3D];
};


Regards.
Last edited on
Don't use the extern keyword for structs or their members.
OK, but it still does not permit me to define pres[n3D] or all[n3D]. Says that n3D should be a constant but it is a constant already.
Last edited on
You can define the constants in the header. The linker won't complain.
Topic archived. No new replies allowed.