Pre-declaration of the class in header files

Player.h

#ifndef PLAYER_H
#define PLAYER_H
class ResourcePack
{
protected:
// something
};

class Player : ResourcePack
{
public:
// something
};
#endif

Render.h

#ifndef RENDER_H
#define RENDER_H

#include <vector>

class ResourcePack;
class Player : ResourcePack; // Синтаксическая ошибка

class Render
{
public:
    ::std::vector<Player>& rfvPlayer;
};

#endif

Optional - Machine. h

#ifndef MACHINE_H
#define MACHINE_H

#include <vector>
#include "Player.h"

class Machine
{
public:
::std::vector<Player> vPlayer;
};
#endif

Afterwards, I collect all the header files in one header file.

#ifndef GAMEKERNEL_H
#define GAMEKERNEL_H

#include "Machine.h"
#include "Render.h"

// something

#endif

How can I pre-declare the Player class in the Render.h file (since it inherits from the ResourcePack class, nothing comes out)?

Author: dreamIIx, 2020-03-30

1 answers

In the case of preliminary inheritance, they do not specify who is inherited from whom. Just the word class, the class name, and a semicolon.

 2
Author: KoVadim, 2020-03-30 19:54:35