C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了c – 错误:字段类型不完整大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
quaternion.h:15:错误:字段’v’的类型不完整

嗨!我陷入了一个似乎无法解决错误.

以下是我的代码

#ifndef QUATERNION_H
#define QUATERNION_H

#include "vec3.h"

class Vec3;

class Quaternion
{

public:

 Quaternion(Vec3 v);

 Quaternion(double w,Vec3 v);

 Vec3 v; <--------------------------This is where the error is :(

 double scalar;



 Quaternion operator *(Quaternion s);

 Quaternion conjugate();

};



#endif

我的Vec.h看起来像这样

#ifndef VEC3_H

#define VEC3_H



#include "point.h"

#include "quaternion.h"

#include <math.h>

class Quaternion;


class Vec3

{

 friend ofstream& operator <<(ofstream& output,const Vec3& p);

 friend ifstream& operator >>(ifstream& input,Vec3& p);



 public: 

 Vec3();

 Vec3(double _x,double _y);

 Vec3(double _x,double _y,double _z);



 double x,y,z;



 //Operators

 Vec3 operator -(Vec3 a) const;

 Vec3 operator /(double s) const;

 Vec3 operator *(double s) const;

 Vec3 operator *(Quaternion q) const;



 // Used to do vector Vec3 addition

 Vec3 operator +(Vec3 a) const;

 Point operator +(Point a) const;



 Vec3& operator =(Point a);



 Vec3 crossProduct(Vec3 v1); // Itself cross v1

 double dotProduct(Vec3 v);

 double length();

 void normalize();


};



#endif

再次感谢您的帮助=)

解决方法@H_404_16@
好吧,你有循环包含两个头文件:vec3.h和quaternion.h.包含警卫将确保每个标头只包含一次.其中一个将首先包括在内,另一个 – 第二个.在您的情况下,首先包含quaternion.h,这意味着Vec3在其中变为不完整的类型.这就是编译器告诉你的.

由于您尝试将Vec3对象用作Quaternion对象的直接成员,因此绝对需要Vec3为完整类型. quaternion.h标头必须包含vec3.h标头.该

class Vec3;

声明在quaternion.h中完全没有,所以你可删除它.

鉴于上述情况,因此vec3.h不能包含quaternion.h,或者你最终会得到循环包含,它永远不会实现任何目标.从vec3.h中删除了quaternion.h的包含.保持

class Quaternion;

在vec3.h中声明并查看它是否以这种方式工作.

大佬总结

以上是大佬教程为你收集整理的c – 错误:字段类型不完整全部内容,希望文章能够帮你解决c – 错误:字段类型不完整所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。