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

Author Topic: No LoadFromX constructors design choice  (Read 1891 times)

0 Members and 1 Guest are viewing this topic.

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
No LoadFromX constructors design choice
« on: May 05, 2011, 06:50:55 am »
Why do classes like sf::Image not have overloaded constructors that implicitly call LoadFromX where X could be, for example, File?

I'm not suggesting this feature, but I'm questioning the design choice to not include it in order review my own choices in my application.

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
No LoadFromX constructors design choice
« Reply #1 on: May 05, 2011, 07:23:15 am »
I believe this was to avoid situations where a constructor could fail. As functions can alert if they fail(with return values). Constructors cannot.

Laurent may confirm if he stops by this thread.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
No LoadFromX constructors design choice
« Reply #2 on: May 05, 2011, 07:29:47 am »
That's the main reason, yes. Since SFML doesn't use exceptions, it can't have constructors that may fail.

The other reason is that things are less explicit, what the constructors does must be deduced from the parameters. And sometimes there are two different LoadFromXxx functions that take the same set of parameters (like in sf::Shader) -- in this case, using a constructor is impossible.
Laurent Gomila - SFML developer

 

anything