-1

I'm writing an application with C++ and OpenGL. In this header file, I just want to make an object from the ObstacleSConnection class in my ObstacleS class, but I get these three errors.

  1. syntax error: missing ';' before

  2. unexpected token(s) preceding ';'

  3. missing type specifier - int assumed. Note: C++ does not support default-int

Since I'm new in c++ and I know my mistake is so simple, can you please help me.

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

};
Nahid
  • 27
  • 7
  • 1
    missing includes for the types used in your header? – Thomas Nov 23 '19 at 09:07
  • 2
    [What are forward declarations in C++?](https://stackoverflow.com/questions/4757565/what-are-forward-declarations-in-c) – Evg Nov 23 '19 at 09:08

1 Answers1

1

C++ does not know ObstacleSConnection when you are using it to define a pointer in ObstacleS class earlier than defining ObstacleSConnection. That is because of the order of defining these two classes. So you need forward declaration of ObstacleSConnection in your code. Just use the line below before ObstacleS class.

class ObstacleSConnection;

You can read more about forward declaration here.

Iman Kianrostami
  • 482
  • 3
  • 13