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

时间:2019-11-23 09:00:44

标签: c++

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

  1. 语法错误:缺少';'

  2. 之前 ';'

    之前的
  3. 个意外令牌

  4. 缺少类型说明符-假定为int。注意:C ++不支持 default-int

由于我是c ++的新手,所以我知道我的错误很简单,请您帮忙。

ObstacleS.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_;

};

1 个答案:

答案 0 :(得分:1)

当您使用C ++在定义ObstacleSConnection之前在ObstacleS类中定义指针时,C ++不知道。这是因为定义这两个类的顺序。因此,您需要在代码中预先声明ObstacleSConnection。只需在ObstacleSConnection类之前使用下面的行。

ObstacleS

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