我在以下文件上遇到了一点问题:
我在这个文件中有arcball结构:
#ifndef ARCBALL_H_
#define ARCBALL_H_
#include "ex1.h"
...
extern struct arcball{
float radius;
int x,y;
}arcball;
...
#endif /* ARCBALL_H_ */我有以下ex1.h文件,其中包含arcbal.h文件:
#ifndef __EX1_H__
#define __EX1_H__
////////////////////////////
// Project Includes
////////////////////////////
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include "arcball.h"
////////////////////////////
// OpenMesh Includes
////////////////////////////
#include "OpenMesh/Core/IO/MeshIO.hh"
#include "OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh"
////////////////////////////
// GL Includes
////////////////////////////
#include "GLee.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
...
struct arcball arcball;
#endif我必须包含ex1.h头文件,因为ex1.h包含了我在arcball.cpp文件中使用的glut函数。为了使用定义在该文件上的函数和结构,我必须使用arcbal.h头文件。
我得到的错误如下:
In file included from arcball.h:11:0,
from arcball.cpp:8:
ex1.h:120:16: error: aggregate ‘arcball arcball’ has incomplete type and cannot be defined
make: *** [ex1] Error 1我不明白为什么它是一个不完整的类型,因为我包含了arcbal.h文件
这是一个相互包含问题还是结构定义/使用问题?又该如何解决呢?
谢谢!
发布于 2012-11-18 04:51:24
这两个.h文件相互包含,导致了很多混淆。这是一个非常糟糕的主意,因为根据首先包含哪个文件,arcball.h-but-really-nothing-because-of-the-#ifdef.周围的#ifdef会产生不同的效果:在本例中,是arcbal.h -> ex1.h -> arcball.h
此外,在头文件(这里是ex1.h)中声明一个没有extern的变量也不是一个好主意。这可能不会产生您想要的效果。不带extern的变量只能在.c文件中声明。
https://stackoverflow.com/questions/13433023
复制相似问题