SFML community forums

Help => Graphics => Topic started by: 51423benam on December 31, 2017, 12:04:30 pm

Title: I can handle sf::Drawable only with pointers?
Post by: 51423benam 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)?
Title: Re: I can handle sf::Drawable only with pointers?
Post by: Laurent 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.
Title: Re: I can handle sf::Drawable only with pointers?
Post by: 51423benam 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.