SFML community forums
Help => General => Topic started by: Wizzard 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.
-
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.
-
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.