首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >聚合“arcball arcball”的类型不完整,无法定义

聚合“arcball arcball”的类型不完整,无法定义
EN

Stack Overflow用户
提问于 2012-11-18 01:37:15
回答 1查看 1.5K关注 0票数 0

我在以下文件上遇到了一点问题:

我在这个文件中有arcball结构:

代码语言:javascript
复制
#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文件:

代码语言:javascript
复制
#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头文件。

我得到的错误如下:

代码语言:javascript
复制
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文件

这是一个相互包含问题还是结构定义/使用问题?又该如何解决呢?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 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文件中声明。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13433023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档