1

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.

5
  • 1
    I'm not sure extern const int MAX_LEN = 4033; makes a lot of sense. If it's an extern variable, you shouldn't be giving it a value! Commented Aug 31, 2010 at 20:25
  • Ahh yes. I fixed that. Still have the same errors. Commented Aug 31, 2010 at 20:28
  • The main problem has been addressed by the answers given by others. However, I thought I should point out that your header file is a bit weird in other ways. It doesn't make any sense to perform assignments (e.g. AllData[index].StartCode = sc;) in a header unless you happen to be #include-ing it directly into the body of a function. Commented Aug 31, 2010 at 20:33
  • Well its a windows form application and when I tried to assign button_click, etc, it placed it in the Form1.h file so thats what I've been working out of. Should I move this to the cpp file? Commented Aug 31, 2010 at 20:46
  • Oh, if you have inline class member functions in your header file, then it does make sense... Commented Aug 31, 2010 at 20:51

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.