我在处理以下文件时遇到一些问题:
我在这个文件上有 arcball 结构:
#ifndef ARCBALL_H_
#define ARCBALL_H_
#include "ex1.h"
...
extern struct arcball{
float radius;
int x,y;
}arcball;
...
#endif /* ARCBALL_H_ */
我有以下包含 arcball.h 文件的 ex1.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 header ,因为 ex1.h 包含了过剩函数 I 也在 arcball.cpp 文件中使用。 我必须使用 arcball.h header 才能使用函数和结构 在该文件上定义。
我得到的错误如下:
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
我不明白为什么它是一个不完整的类型,因为我包含了 arcball.h 文件
这是相互包含问题还是结构定义/使用问题? 如何解决?
谢谢!
最佳答案
这两个 .h
文件相互包含,造成了很多困惑。这是一个非常糟糕的主意,因为周围的 #ifdef
会根据首先包含的文件产生不同的效果:在这种情况下,arcball.h -> ex1.h -> arcball.h-但是-真的什么都没有,因为-#ifdef。
此外,在 header 中声明一个没有 extern
的变量也是一个坏主意(这里是 ex1.h)。这可能没有达到您想要的效果。没有 extern
的变量只能在 .c
文件中声明。
关于c++ - 聚合 ‘arcball arcball’ 类型不完整,无法定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13433023/