Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: When to use {} () in constructors  (Read 1025 times)

0 Members and 1 Guest are viewing this topic.

Powereleven

  • Newbie
  • *
  • Posts: 36
    • View Profile
When to use {} () in constructors
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: When to use {} () in constructors
« Reply #1 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".
Laurent Gomila - SFML developer