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

Author Topic: I can handle sf::Drawable only with pointers?  (Read 3191 times)

0 Members and 1 Guest are viewing this topic.

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
I can handle sf::Drawable only with pointers?
« on: December 31, 2017, 12:04:30 pm »
Hello,

I have a class "Container", which is just a Container for self-written widgets derived from sf::Drawable. It has a vector, which holds them. Also, I have the class "GUIManager", which is a class containing ALL widgets of the GUI (also in a vector). It has a function to add a Container to the GUI, in which all widgets from the vector of the Container are copied to his vector of all widgets.

I made the whole thing with shared_ptr s, because it seemed handy to me. So in the vectors of the Containers and also of the GUIManager are shared_ptr s to the widgets. But that becomes a problem more and more and gets to complicated, so I tried to store the widgets normal, without pointers, and just pass pointers of them to the GUIManager.
But I can't declare normal variables to classes derived from sf::Drawable, because sf::Drawable is a abstract class.
How can I do this (store object from classes derived from sf::Drawable in a normal variable)?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I can handle sf::Drawable only with pointers?
« Reply #1 on: December 31, 2017, 12:26:27 pm »
You can't. Lookup "object slicing" on Google to know more about the problems it would produce.

What's "complicated" with smart pointers? If you use them correctly, things should be simple.
Laurent Gomila - SFML developer

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: I can handle sf::Drawable only with pointers?
« Reply #2 on: January 01, 2018, 02:24:18 pm »
Ok, I've looked it up, but I don't understand, why this is only causing problems in relationship to normal variables and not to pointers.

 

anything