c++ - 聚合 ‘arcball arcball’ 类型不完整,无法定义

标签 c++ struct include extern

我在处理以下文件时遇到一些问题:

我在这个文件上有 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/

相关文章:

c++ - R/为R编译c代码

c++ - 无法恢复作为礼物赠送的 lifetimevirtualgood 项目

c++ - 使用默认函数参数的优点

C++ 逐字符比较字符串

c# - struct 与 for 循环的使用

jsp - 是否可以将动态路径作为 jsp include 的一部分

c++ - 使用 MFC 中的异步过程调用中断接受 winsock 调用

arrays - 检查具有数组字段的空结构

c++ - 具有预处理器分支实现的结构是否违反了 ODR?

include - 在 Jekyll 中,include_relative 是如何处理布局文件的?