external structure in a structure

Hello,

I wrote in a library (weighing.h) a structure..

struct MASTER_STRUCT{
	unsigned char hivesNumber;
	unsigned char scalesI2cAddress[MAX_NB_SLAVES];
	unsigned int period;	// in sec
	unsigned char nbSamples;
	unsigned char beginHour;
	unsigned char endHour;
	DATA_FORWARDER data_forwarder;
};

but, I would like to declare the DATA_FORWARDER structure in an other *.h file.

My problem is the weighing.h is a generic file. and I want to have a specific part in an other file.
So I can use the generic file for many projects, each one with a specific header...

So, I will be very happy if somebody can help to solve my problem...

Best regards,

Thierry

Are you getting an error with that? Can you show the other .h file?

Hello the other structur for now is very simple (but in an other *.h file)

struct DATA_FORWARDER{
int x;
};

and the compiler error is:

error: ‘DATA_FORWARDER’ does not name a type
DATA_FORWARDER data_forwarder;

Best regards and many thanks for your help.
Thierry

Is that included in both the header that needs it AND the sketch?

No ! just in the sketch !
Because I dont want to have an specific include in the generic header......

Is that any way more elegant to solve this problem ? (generic and specific structure and no specific include file in the generic header)

Best regards

Thierry

Nope. If you want that type to exist in that header then you have to include it there.

Vorms:
Best regards and many thanks for your help.
Thierry

struct DATA_FORWARDER{
int x;
};

struct MASTER_STRUCT : public DATA_FORWARDER{
 unsigned char hivesNumber;
 unsigned char scalesI2cAddress[];
 unsigned int period; // in sec
 unsigned char nbSamples;
 unsigned char beginHour;
 unsigned char endHour;
 DATA_FORWARDER data_forwarder;
};


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

The compilation error for this version is:

error: expected class-name before '{' token
struct MASTER_STRUCT: public DATA_FORWARDER{
^

Thierry

You can define the DATA_FORWARDER structure BEFORE including the header for MASTER_STRUCT, but I suspect the goofy Arduino build process will wreak havoc with that. Perhaps you could get away with this:

MASTER_STRUCT.h, located in the MASTER_STRUCT “library” directory:

#include "DATA_FORWARDER.h"

struct MASTER_STRUCT
{
   ....
{;

DATA_FORWARDER.h, located in the sketch directory

struct DATA_FORWARDER
{
    ....
};

Your sketch:

#include <MASTER_STRUCT.h>

Not sure if that will work with the Arduino build process, but it’s worth a try.

Regards,
Ray L.