SFML community forums

Help => General => Topic started by: sill49 on July 29, 2018, 06:26:04 pm

Title: Inheriting from sf::Drawable.
Post by: sill49 on July 29, 2018, 06:26:04 pm
Hi there. I'm currently implementing a game of cards in SFML. Obviously, I would like to draw some cards, and I need my object-oriented design to be as flexible as possible for further development.

Therefore, I considered to inherit the Card class from sf::Drawable. The problem is that my Card constructor is constexpr and the sf::Drawable's constructor is not. At least that's what I understand from the error message: constexpr constructor calls non-constexpr function sf::Drawable::Drawable() noexcept".

I could take away the constexpr specifier from the constructor, but there are other pieces of code that rely on that constexpr constructor.

What would be your advice for me? Thanks in advance.
Title: Re: Inheriting from sf::Drawable.
Post by: eXpl0it3r on July 29, 2018, 06:42:21 pm
Why does the constructor need to be constexpr?
Title: Re: Inheriting from sf::Drawable.
Post by: sill49 on July 29, 2018, 06:55:09 pm
It doesn't need to be constexpr, but it's a nice addition. For example, I have an array of 52 cards (the default deck) which can be resolved at compile-time.
Title: Re: Inheriting from sf::Drawable.
Post by: Mario on July 30, 2018, 08:24:23 pm
Just delay the construction of the SFML resources past the actual constructor? You can't really create stuff like OpenGL contexts at compile time anyway.