结构声明范围

时间:2016-06-10 08:36:37

标签: c++ scope compiler-errors structure directory

我已将项目划分为此源文件夹:

src/
src/THREADS
src/UKF_IMU+GPS
src/UKF_WCT

我已在此文件中声明了结构" src / UKF_IMU + GPS / main_general.h"

main_general.h

//Structure Declarations
struct FD
{
int IMU, GPS;
};

struct S_POS
{
double X=0, Y=0, Z=0;
double Latitude=0, Longitude=0, Altitude=0;
};

struct S_IMU
{
double ACCX=0, ACCY=0, ACCZ=0, GYRX=0, GYRY=0, GYRZ=0;
double ACCX_Bias=0, ACCY_Bias=0, ACCZ_Bias=1, GYRX_Bias=0, GYRY_Bias=0, GYRZ_Bias=0;
double Pitch=0, Roll=0, Yaw=0;

//Variables to Calculate AT
double AT=0;
unsigned int Time=0;
};

struct S_GPS
{
int Date=0, TimeHour=0, NumSatUsed=0;

double Yaw=0, Velocity, Vel_X=0, Vel_Y=0, Vel_Z=0;
double Std_Dev_Lat=0, Std_Dev_Lon=0, Std_Dev_Alt=0;
double HDOP=0;

//Variables to Calculate AT
double AT=0;
unsigned int Time=0;
};

然后,我在" /src/THREADS/IMUandGPS.cpp"

中声明了一个结构全局变量对象

IMUandGPS.cpp

#include "../UKF_IMU+GPS/main_general.h"

/* Global variables */
struct S_POS POS_Snapshot;
struct S_IMU IMU_Snapshot;
struct S_GPS GPS_Snapshot;

我做了一些结构的东西,它很完美。

我也在另一个文件中使用相同的全局对象" /src/THREADS/Write_IMUAndGPS_OF.cpp"

Write_IMUAndGPS_OF.cpp

#include "../UKF_IMU+GPS/main_general.h"

/* External Global variables */
extern struct S_POS POS_Snapshot;
extern struct S_IMU IMU_Snapshot;
extern struct S_GPS GPS_Snapshot;

我做了一些结构的东西,它也很完美。

问题来了,我必须在这个文件中使用POS全局结构: " /src/src/UKF_WCT/UKF_Algorithm.cpp"

UKF_Algorithm.cpp

#include "../UKF_IMU+GPS/main_general.h"

/* External Global variables */
extern struct S_POS POS_Snapshot;

PosX = POS_Snapshot.Latitude;
PosY = POS_Snapshot.Longitude;
PosZ = POS_Snapshot.Altitude;

包含和一切都相同,但编译器给我一个错误:

forward declaration of 'struct S_POS'   UKF_Algorithm.cpp   
invalid use of incomplete type 'struct S_POS'   UKF_Algorithm.cpp   
invalid use of incomplete type 'struct S_POS'   UKF_Algorithm.cpp
invalid use of incomplete type 'struct S_POS'   UKF_Algorithm.cpp

PosX,Y和Z也是双倍因此不是类型问题......为什么会出现这个问题?

1 个答案:

答案 0 :(得分:1)

我已经解决了!

问题是我在“src / UKF_WCT / main_general.h”中有另一个main_general.h文件,因此编译器找到了这个文件而不是“/UKF_IMU+GPS/main_general.h”。

我更改了文件的名称,它完美无缺!