I am reading the book "Game Programming in C++" by Sanjay Madhav, and it is very frequent, almost constant, to see how instead of using includes in the interfaces of the classes, he uses the keyword "class" before the type that he intends to use so that the compiler accept it. I haven't seen it done anywhere else, and I don't know if it's okay. It works.
Does this technique have a name? Is it like forward declaration?
Example:
#pragma once
#include <vector>
#include "Math.h"
#include <cstdint>
class Actor
{
public:
enum State
{
EActive,
EPaused,
EDead
};
Actor(class Game* game);
virtual ~Actor();
// Update function called from Game (not overridable)
void Update(float deltaTime);
// Updates all the components attached to the actor (not overridable)
void UpdateComponents(float deltaTime);
// Any actor-specific update code (overridable)
virtual void UpdateActor(float deltaTime);
// ProcessInput function called from Game (not overridable)
void ProcessInput(const uint8_t* keyState);
// Any actor-specific input code (overridable)
virtual void ActorInput(const uint8_t* keyState);
// Getters/setters
const Vector3& GetPosition() const { return mPosition; }
void SetPosition(const Vector3& pos) { mPosition = pos; mRecomputeWorldTransform = true; }
float GetScale() const { return mScale; }
void SetScale(float scale) { mScale = scale; mRecomputeWorldTransform = true; }
const Quaternion& GetRotation() const { return mRotation; }
void SetRotation(const Quaternion& rotation) { mRotation = rotation; mRecomputeWorldTransform = true; }
void ComputeWorldTransform();
const Matrix4& GetWorldTransform() const { return mWorldTransform; }
Vector3 GetForward() const { return Vector3::Transform(Vector3::UnitX, mRotation); }
State GetState() const { return mState; }
void SetState(State state) { mState = state; }
class Game* GetGame() { return mGame; }
// Add/remove components
void AddComponent(class Component* component);
void RemoveComponent(class Component* component);
private:
// Actor's state
State mState;
// Transform
Matrix4 mWorldTransform;
Vector3 mPosition;
Quaternion mRotation;
float mScale;
bool mRecomputeWorldTransform;
std::vector<class Component*> mComponents;
class Game* mGame;
};