有谁知道这段代码有什么问题?

Does anyone know what is the problem in this code?

本文关键字:什么 问题 代码 谁知道 段代码      更新时间:2023-10-16

我正在用C++和OpenGL编写一个应用程序。在这个头文件中,我只想从我的 ObstacleS 类中的 ObstacleSConnection 类创建一个对象,但我得到这三个错误。

  1. 语法错误:前面缺少";"

  2. ";"前面的意外标记

  3. 缺少类型说明符 - 假定为 int。注意:C++不支持 默认整型

由于我是 c++ 的新手,我知道我的错误很简单,你能帮帮我吗?

障碍S.h

#pragma once
#pragma warning

class ObstacleS
{
public:
ObstacleS(cyclone::Vector3& p);
~ObstacleS();
ObstacleSConnection * sconnection;  (error is here)
cyclone::Vector3 m_color;
cyclone::Particle* m_particle;
cyclone::ParticleForceRegistry* m_forces;
void update(float duration);
void draw(int shadow);
};
class ObstacleSConnection
{
public:
ImplicitEngine* _engine;

int  MAX_CONTACTS = 5000;
int numStatics;
ObstacleSConnection(int n);
~ObstacleSConnection();
std::vector<cyclone::ParticleContactGenerator*> m_grounds;
cyclone::ParticleContactResolver* m_resolver;
std::vector<ObstacleS*> m_statics;
size_t addObstacle(const std::vector<cyclone::Vector3>& vertices);
std::vector<Obstacle*> obstacles_;
};

C++不知道ObstacleSConnection何时使用它在类中定义指针ObstacleS而不是定义ObstacleSConnection。这是因为定义这两个类的顺序。因此,您需要在代码中向前声明ObstacleSConnection。只需在上课前使用下面的行ObstacleS即可。

class ObstacleSConnection;

您可以在此处阅读有关前向声明的更多信息。