0

次のファイルに少し問題があります。

私はこのファイルにアークボール構造体を持っています:

#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 には、arcball.cpp ファイルでも使用する glut 関数のインクルードが含まれているため、ex1.h ヘッダーを含める必要があります。そして、関数を使用するために arcball.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

arcball.h ファイルを含めたので、なぜ不完全型なのかわかりません

これは相互包含の問題ですか、それとも構造体の定義/使用の問題ですか? そして、それはどのように解決できますか?

ありがとう!

4

1 に答える 1

1

2つの.hファイルは互いに含まれているため、多くの混乱が生じます。これはひどく悪い考え#ifdefです。最初に含まれるファイルに応じて周囲の効果が異なるためです。この場合、arcball.h-> ex1.h-> arcball.h-but-really-nothing-because-of-the -#ifdef。

さらに、externヘッダー(ここではex1.h)を使用せずに変数を宣言することもお勧めしません。それはおそらくあなたが望む効果を持っていません。のない変数は、ファイルexternでのみ宣言する必要があり.cます。

于 2012-11-17T20:51:24.320 に答える