[英](structname/classname) does not name a type C++
I have an issue with my structs and classes not having a "type" My code looks like this, I will show for one error:我的结构和类没有“类型”有问题我的代码看起来像这样,我将显示一个错误:
This my struct "intersection" declared under my "Vector" class in vector.h:这是我在 vector.h 中的“Vector”类下声明的结构“intersection”:
struct Intersection {
bool hasIntersection;
Shape *pShape;
float t;
Color color;
Intersection emptyIntersection();};
Then this is my include in Shape.cpp where I have a subclass structure with different shapes:然后这是我在 Shape.cpp 中的包含,其中我有一个具有不同形状的子类结构:
#include "../include/Shape.h"
This is one of the functions:这是其中一项功能:
Intersection Sphere::intersect(const Ray &ray) {
// Sphere naar nul zetten
Ray localray = ray;
localray.origin -= centre;
Intersection localintersection{};
float a = localray.direction.length2();
float b = 2 * localray.direction.dot(localray.origin);
float c = localray.origin.length2() - sqr(radius);
float D = sqr(b) - 4 * a * c;
if (D < 0.0f){
return localintersection.emptyIntersection();
}
float t1 = (-b - std::sqrt(D)) / (2 * a);
float t2 = (-b + std::sqrt(D)) / (2 * a);
if (t1 > RAY_T_MIN && t1 < RAY_T_MAX) {
localintersection.hasIntersection = true;
localintersection.pShape = this;
localintersection.color = color;
localintersection.t = t1;
}
else if(t2 > RAY_T_MIN && t2 < RAY_T_MAX) {
localintersection.t = t2;
}
else{
return localintersection.emptyIntersection();
}}
And this is the top part of my Shape class in Shape.h这是我在 Shape.h 中的 Shape 类的顶部部分
virtual Intersection intersect(const Ray& ray) = 0;
It is giving me the errors that 'Shape' does not name a type for my struct, and Intersection does not name a type for my Shape.h class.它给我的错误是“Shape”没有为我的结构命名类型,而 Intersection 没有为我的 Shape.h 类命名类型。 I do not know how to solve it, I have seen many other topics which have solutions, but none of these work
我不知道如何解决它,我看到了许多其他有解决方案的主题,但这些都不起作用
EDIT:编辑:
declaration of Shape and a subclass Shape 和子类的声明
class Shape {
public:
virtual Intersection intersect(const Ray& ray) = 0;
};
class Shapeset : public Shape{
protected:
std::vector<Shape*> shapes;
public:
Shapeset();
void addShape (Shape* shape);
virtual Intersection intersect(const Ray& ray);
};
Your header with Intersection declaration doesn't have Shape declaration.带有 Intersection 声明的标题没有 Shape 声明。
Use code:使用代码:
class Shape;
struct Intersection { ...
There is same trouble with Shape header: header doesn't have Intersection declaration. Shape header 也有同样的问题:header 没有 Intersection 声明。 I recommend you to include intersection header into shape header.
我建议您将交集标题包含在形状标题中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.