1

Kinda of a hard question to summarize. I have an Entity class that has a Move class object as a member. The Move class has a variable of a class that takes an Entity in a function, is there a way to include the class that takes Entity in a function in move without trouble? Since Move is undefined when you include the class that takes an entity.

Here's an example.

Entity.h

#pragma once
#include "Move.h"


class Entity
{
    public:
        Entity();

    protected:

    private:
        Move move_var;
};

Move.h

#pragma once
#include "TakesAnEntity.h"

class Move
{
    public:
        Move();
        TakesAnEntity obj;

    protected:

    private:
};

TakesAnEntity.h

#pragma once
#include "Entity.h"

class TakesAnEntity
{
    public:
        TakesAnEntity();
        void Func(Entity entity_obj);

    protected:

    private:
};

Any help is appreciated.

DL-48
  • 21
  • 2
  • 2
    In `TakesAnEntity.h`, don't `#include "Entity.h"`. A forward declaration is sufficient, as in `class Entity;` – Igor Tandetnik Oct 05 '20 at 00:35
  • See the linked duplicate question for more information on what forward declarations are, for both functions and classes, and how to use them. Some of the examples in some of the answers there are pretty much the same as yours'. – Sam Varshavchik Oct 05 '20 at 00:36

0 Answers0