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

Author Topic: Inheriting from sf::Drawable.  (Read 3149 times)

0 Members and 1 Guest are viewing this topic.

sill49

  • Newbie
  • *
  • Posts: 2
    • View Profile
Inheriting from sf::Drawable.
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Inheriting from sf::Drawable.
« Reply #1 on: July 29, 2018, 06:42:21 pm »
Why does the constructor need to be constexpr?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

sill49

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Inheriting from sf::Drawable.
« Reply #2 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.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Inheriting from sf::Drawable.
« Reply #3 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.

 

anything