我与这个主cpp文件:的extern问题结构C++的阵列
#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];
然后我有以下内容的form.h:
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;
...
这不会给编译大量的错误,但第一个是:'DataLine *' : unknown size
。我应该改变某些东西给typedef吗?我不确定为什么它不喜欢这个。
我不确定'extern const int MAX_LEN = 4033;'很有意义。如果它是一个'extern'变量,你不应该给它一个价值! – 2010-08-31 20:25:13
啊,是的。我修正了这一点。仍然有相同的错误。 – 2010-08-31 20:28:14
主要问题已由其他人给出的答案解决。但是,我想我应该指出你的头文件在其他方面有点奇怪。在一个头文件中执行赋值(例如'AllData [index] .StartCode = sc;')没有任何意义,除非碰巧直接将'#include'包含在函数的主体中。 – 2010-08-31 20:33:05