Saturday, 21 January 2017

c++ - What does a semicolon after a class name do?





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?


Answer



These are forward declarations. They let the following code know that there is 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.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...