SFML community forums

Help => General => Topic started by: Powereleven on January 29, 2018, 06:18:23 am

Title: When to use {} () in constructors
Post by: Powereleven on January 29, 2018, 06:18:23 am
I have in Game.h a class Game. In private: sf::RenderWindow app;
Then in Game.cpp I use:
Game::Game() : app({1000,800},"NAME")
{
}
The syntax
Game::Game() : app(sf::VideoMode(1000,800),"NAME")
{
}
also works.
My question is: why can you omit sf::VideoMode in the first case, and if you do so, why do you HAVE to use {} for the videomode parameters? Using () In the first case results in an error.
Title: Re: When to use {} () in constructors
Post by: Laurent on January 29, 2018, 08:14:04 am
This is basic C++ syntax, you should rather read about it (I'm sure you can find useful articles on Google, or short explanations on stackoverflow). Don't forget that this is the SFML forum, we don't teach C++ ;)

Hint: lookup these keywords "C++11 brace initialization".