I've noticed lines of code like this in the book I'm reading:
namespace sf
{
class RenderWindow;
}
class StateStack;
class Player;
class State
{
// Code for the class
};
What do the lines with just the class, classname, and semicolon mean?
I've noticed lines of code like this in the book I'm reading:
namespace sf
{
class RenderWindow;
}
class StateStack;
class Player;
class State
{
// Code for the class
};
What do the lines with just the class, classname, and semicolon mean?
These are forward declarations. They let the following code know that there are classes with the names RenderWindow
, StateStack
, and Player
. This satisfies the compiler when it sees these names used. Later the linker will find the definition of the classes.
It is a forward declaration, essentially it signals to the compiler that the full definition will follow elsewhere.
The primary use case for this is cases where you do not need the full definition, for example if you have a pointer of type T
you don't need the full definition of T
until instantiation and thus its not required to have for a declaration of T*
.