That's called a member initialization list. They're part of the C++ language. A member initialization list allows you to initialize members during class initialization. One reason why they're good practice is because they allow you to initialize const
members when assigning won't work. For example, the following class definition won't work because const int member1
wasn't initialized with a value, nor can you assign to a const int
because const
makes it read-only.
class Game{
private:
const int member_var; //won't work, needs to be initialized
int member_var2;
public:
Game() {} //Game constructor
};
With initialization lists, you're able to initialize const
members like these and other variables by adding a colon after your constructor definition (but before the brackets to define it) and initializing members as needed, either with direct initialization (using "()") or uniform initialization (using "{}"). To initialize multiple members, separate them with a comma.
class Game{
private:
const int member_var;
int member_var2;
public:
Game(): member_var(1), member_var2(2) {}
//Uniform initialization is ": member_var{1}, member_var{2}"
};
In your example, the Game()
constructor was defined outside the class definition (likely in another .cpp file) via Game::Game()
with a member initialization list. I'm guessing _window
is a class with one constructor that takes sf::VideoMode(800,600)
and "SFML Title"
as arguments.