views:

34

answers:

2

I have the main .cpp file with this:

#include "stdafx.h"
#include "Form1.h"
#include <iostream>
...
#include <stdio.h>

const int MAX_LEN = 1000;

struct DataLine {
    char StartCode;
    int ByteCount;
    int Address;
    int RecType;
    int DBytes[16];
    int Checksum;
};
DataLine AllData[MAX_LEN];  

Then I have a form.h with the following:

extern const int MAX_LEN;  
extern struct DataLine AllData[MAX_LEN]; 
//later on in header file  
AllData[index].Startcode = sc;
AllData[index].ByteCount = i_Byte_Count;  
...

This will not compile giving a host of errors but the first is: 'DataLine *' : unknown size. Should I change certain things to typedef? I'm not really sure why its not liking this.

+1  A: 

You can't define

extern struct DataLine AllData[MAX_LEN];

in the header file because struct DataLine is completely unknown in the header file. No typedef will help you here. The definition of struct DataLine must be present in the header file before you define AllData. Move it there.

AndreyT
+1  A: 

Because the declaraction of struct DataLine has to be form.h before the definition of AllData

Basically, you are saying to your other files, that they could say:

 DataLine* pre = &AllData[5];

Now, how could the compiler know where far from the start of AllData that item is, unless it knows exactly how big each DataLine is?

James Curran