另一个不完整的类型错误C
another incomplete type Error C++
可能的重复:
循环依赖/不完整类型
编写一个litte c 程序并感到困惑....
有4个类,2对于此错误很重要...
在第13行和" Expect';'"中获取错误消息" field'Dot'具有不完整的类型"。befor'(" token"同一行
错误似乎从vector3.CPP开始,其中仅包括vector3.h和空方法
删除了正常3个标头中的包含" vector3.h",思想将在一个圆圈中运行...
一些想法?希望如此:)和ty for Answers
这是我的两个重要课程:
#ifndef NORMAL3_H
#define NORMAL3_H
class Normal3 {
public:
double x, y, z;
Normal3 mul(Normal3 n);
Normal3 add(Normal3 n);
Normal3 dot(Vector3 v); //Line 13
Normal3(double x = 0, double y = 0, double z = 0)
: x(x), y(y), z(z)
{ }
};
#endif //NORMAL3_H
aaaaaaaaaaaaaaaaaaaaaaaaand
#ifndef VECTOR3_H
#define VECTOR3_H
#include "Normal3.h"
class Vector3 {
public:
double x, y, z, magnitude;
Vector3 add(Vector3 v);
Vector3 add(Normal3 n);
Vector3 sub(Normal3 n);
Vector3 mul(double c);
double dot(Vector3 c);
double dot(Normal3 n);
Vector3 normalized();
Normal3 asNormal();
Vector3 refelctedOn(Normal3 n);
Vector3(double x = 0, double y = 0, double z = 0, double m = 0)
: x(x), y(y), z(z), magnitude(m)
{ }
};
#endif //VECTOR3_H
它只是意味着编译器当时不知道Vector3
是什么。如果您提前声明,错误将消失:
#ifndef NORMAL3_H
#define NORMAL3_H
class Vector3; // Add this line
class Normal3 {
// ...
};
更新:正如约翰在评论中所说的那样,在vector3.h中替换 #include "Normal3.h"
的良好进步将是另一个远期声明, class Normal3;
:
#ifndef VECTOR3_H
#define VECTOR3_H
class Normal3; // instead of #include "Normal3.h"
class Vector3 {
// ...
};
您应该尝试将#include
指令在标题中保持在最低限度,以避免过度汇编依赖性。您只需要在定义您正在使用的类型时包含标头(通常是因为您定义的类具有此类型的数据成员)。如果您仅使用指示或引用该类型的该类型或功能参数(如示例中),则向前声明就足够了。
您的文件normal3.h
对Vector3
一无所知。
我看到 Vector3 v
不会更改为 dot
,然后您应该写:
而不是Normal3 dot(Vector3 v); //Line 13
AS
#ifndef NORMAL3_H
#define NORMAL3_H
class Vector3;
class Normal3 {
public:
double x, y, z;
Normal3 mul(Normal3 n);
Normal3 add(Normal3 n);
Normal3 dot(const Vector3 &v); //Line 13
Normal3(double x = 0, double y = 0, double z = 0)
: x(x), y(y), z(z)
{ }
};
#endif //NORMAL3_H
相关文章:
- 类没有命名C++代码中的类型错误
- 不完整类型错误(E0409、E0070、E0515)
- 使用具有结构不完整类型错误的模板
- 不命名构造函数和析构函数上的类型错误
- 返回派生类型时出现协变类型错误
- 为什么此构造函数没有给出不完整的类型错误?
- 定义模板化结构的特征时出现不完整的类型错误
- 使用重载构造函数时出现不完整的类型错误
- 为什么我得到表达式必须有类类型错误?
- 输出 [left]=input[i] 行中的 c++ 代码中存在无效的类型错误
- 枚举成员不是类型错误
- 如何修复"ctypes"。参数错误:参数 2:<键入"异常.类型错误">:RaspberryPi 中的错误类型"错误
- 外部 "C" Visual Studio 2015 中的显式类型错误,DLL 测试代码
- 非默认析构函数会导致不完整的类型错误
- 为什么按引用传入会导致绑定引用类型错误
- Objective-C C++ 包装器 类型错误的不完整定义
- 输入类型错误
- 当构造函数的参数类型错误时引发异常
- 命名空间中的'bad_cast' 'std' 未命名类型错误
- C UNWORKOWN类型错误